tags:

views:

40

answers:

2
<?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?

A: 

I don't want to just copy all their code but it's on the website below.

http://www.php-mysql-tutorial.com/wikis/mysql-tutorials/connect-to-mysql-database.aspx

Brian Huenefeld
Thank you sir .Hope it will help me.
Sai kiran
+4  A: 

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());
}
codaddict
thank u sir,hope it may help me a lot
Sai kiran