1<?php
2$enlace = mysqli_connect("127.0.0.1", "mi_usuario", "mi_contraseña", "mi_bd");
3
4if (!$enlace) {
5 echo "Error: No se pudo conectar a MySQL." . PHP_EOL;
6 echo "errno de depuración: " . mysqli_connect_errno() . PHP_EOL;
7 echo "error de depuración: " . mysqli_connect_error() . PHP_EOL;
8 exit;
9}
10
11echo "Éxito: Se realizó una conexión apropiada a MySQL! La base de datos mi_bd es genial." . PHP_EOL;
12echo "Información del host: " . mysqli_get_host_info($enlace) . PHP_EOL;
13
14mysqli_close($enlace);
15?>
1// mysqli_connect is an alias of mysqli::__construct()
2$mysqli = new mysqli("host", "user", "password", "database", 'port', 'socket');
1
2<?php
3$mysqli = new mysqli("localhost","my_user","my_password","my_db");
4
5// Check connection
6if ($mysqli -> connect_errno) {
7
8 echo "Failed to connect to MySQL: " . $mysqli -> connect_error;
9
10 exit();
11
12 }
13?>
1<?php;
2$db_handle = mysqli_connect($db_server_name, $db_user_name, $db_password);
3?>