mysqli_connect

(PHP 5, PHP 7)

mysqli_connectSinônimo de mysqli::__construct()

Descrição

Esta função é um apelido para: mysqli::__construct()

Although the mysqli::__construct() documentation also includes procedural examples that use the mysqli_connect() function, here is a short example:

Exemplos

Exemplo #1 mysqli_connect() example

<?php
$link 
mysqli_connect("127.0.0.1""my_user""my_password""my_db");

if (!
$link) {
    echo 
"Error: Unable to connect to MySQL." PHP_EOL;
    echo 
"Debugging errno: " mysqli_connect_errno() . PHP_EOL;
    echo 
"Debugging error: " mysqli_connect_error() . PHP_EOL;
    exit;
}

echo 
"Success: A proper connection to MySQL was made! The my_db database is great." PHP_EOL;
echo 
"Host information: " mysqli_get_host_info($link) . PHP_EOL;

mysqli_close($link);
?>

Os exemplos acima irão imprimir algo similar à:

Success: A proper connection to MySQL was made! The my_db database is great.
Host information: localhost via TCP/IP
add a note add a note

User Contributed Notes 1 note

up
-47
mparsa1372 at gmail dot com
1 year ago
Example (MySQLi Object-Oriented)

<?php
$servername
= "localhost";
$username = "username";
$password = "password";

// Create connection
$conn = new mysqli($servername, $username, $password);

// Check connection
if ($conn->connect_error) {
  die(
"Connection failed: " . $conn->connect_error);
}
echo
"Connected successfully";
?>
To Top