Documentation Home
MySQL PHP API
Download this Manual
PDF (US Ltr) - 2.8Mb
PDF (A4) - 2.8Mb
EPUB - 456.8Kb
HTML Download (TGZ) - 396.0Kb
HTML Download (Zip) - 409.8Kb


3.15.4 mysqli_connect

Copyright 1997-2014 the PHP Documentation Group.

Description

This function is an alias of: mysqli::__construct

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

Examples

Example 3.137 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);
?>

   

The above examples will output:


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



User Comments
Sign Up Login You must be logged in to post a comment.