Why does mysqli_connect not work, but mysql_connect?

Is there any reason why this could be so?

Here is the code:

$dbc = mysqli_connect (DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
echo $dbc;
if(!$dbc){
die('could not open a connection'.mysqli_connect_errno() . mysqli_connect_error());
}

Again, if I replace mysqli with mysql, I get the dbc resource id returned (I assume this is good). I would like to use mysqli as I hear it much better / faster. Now I am getting error code 2003.

+3
source share
3 answers

mysql_connect()and mysqli_connect()use two different default ports from php.ini file. I would not have guessed that they would differ from the default default 3306, but it is worth checking or trying to add the path to the host URL.

mysqli_connect :

mysqli mysqli_connect (... int $port = ini_get ( " mysqli.default_port" )...)

mysql_connect:

PHP mysql.default_host undefined ( ), "localhost: 3306". SQL "localhost: 3306".

: , .

, , , , . mysqli_connect_errno(). PHP.net.

$mysqli = new mysqli('localhost', 'my_user', 'my_password', 'my_db');

if (mysqli_connect_error()) {
    die('Connect Error (' . mysqli_connect_errno() . ') '
            . mysqli_connect_error());
}

:
OO: . , mysqli_connect_error() mysqli- > connect_error .

a >

+3

consider using

$dbc= new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
0
source

All Articles