code to connect MySQL database and PHP
Posted On at by milanConnecting to MySQL database is very easy and consist of following few instractions.
$host="localhost"; //Mostly its localhost
$dbUser="root";//your mysql username here
$password="passwordhere";// mysql user's password
$dbName="students";//Your MySQL database name
$dbc=@mysql_connect($host,$dbUser,$password) OR die('Couldn\'t connect to MySql:'.mysql_error());//This will make a connection to mysql or will display error if failed
mysql_select_db($dbName, $dbc) OR die('Couldn\'t select DB:'.mysql_error());//This will select the specified database for operations or will display error if failed
?>
Thats it with the above code you are connected to mysql db through php and can perform any mySQL database operation through php script now.