Reputation: 17
<?php
// MySQL database connection file
$SERVER = "127.0.0.1"; // MySQL SERVER
$USER = "root"; // MySQL USER
$PASSWORD = "admin"; // MySQL PASSWORD
$link = @mysql_connect($SERVER,$USER,$PASSWORD);
$db = mysql_select_db("website");
?>
This is a database connecting code for chat program but it not connecting,Can any one pls help me to correct this code?
Upvotes: 1
Views: 220
Reputation: 455030
Drop the @
infront of mysql_connect
, it's used to suppress error which you don't want.
Also you need to check the return value of mysql_connect
which is there in $link
and make sure that it is not false
before you proceed and to a DB select. Calling the function mysql_error
when an error occurs gives you the reason for the error.
$link = mysql_connect($SERVER,$USER,$PASSWORD);
if (!$link) {
die('Could not connect: ' . mysql_error());
}
Upvotes: 4