pita
pita

Reputation: 537

php can't connect to the mysql database

here is my code

 $db_handle = mysql_connect('127.0.0.1', 'root', '123456');
    if(!$db_handle)
        die(mysql_error())

when i was debugging the code just got a page with "This page can't be display", and the a pop up message from netbean said " Socket Exception occured", can anyone help? thanks

edit new code:

$db_handle = new PDO('mysql:host=localhost;dbname=test','admin','123456');
    if($db_handle)
        echo 'connected';

it works, but the mysqli didn't work either

Upvotes: 0

Views: 105

Answers (2)

pita
pita

Reputation: 537

$db_handle = new PDO('mysql:host=localhost;dbname=test','admin','123456'); if($db_handle) echo 'connected';

Upvotes: 0

Fabio
Fabio

Reputation: 23510

Please stop using mysql_query for new project, use mysqli or PDO

Here a sample:

mysqli = new mysqli($host, $user, $dbpassword, $database);
if (mysqli_connect_errno()) 
{
    printf("Connection failed: %s\n", mysqli_connect_error());
    exit();
}

Upvotes: 1

Related Questions