PHP script to test MySQL database Connection
January 1st, 2010
0 Comments
Here is php script to test database Connection, it will need little edition as per your database name and password
Here you go
Just copy and paste below code :-
< ?php ###################################### C O P Y R I G H T S ############################################ # THIS SIMPLE SCRIPT IS DISTRIBUTED BY WWW.MYLITERATURETECHLIFE.COM UNDER LICENSE UNDER THE GPL RULES # # PLEASE DO NOT REMOVE THIS MESSAGE IN SUPPORT OF OUR HARD WORK TO CONTINUE TO PROVIDE FREE SUPPORT # ####################################################################################################### ############ Define hostname ############# ## Replace "localhost" with your mysql host name or Ip address ## define ("HOSTNAME","localhost"); ############ Define username ################### ## Replace "db_usname" with your Database Username ## define ("USERNAME","db_usname"); ############ Define password ################### ## Replace "db_passwd" with your Database password ## define ("PWD","db_passwd"); ############ Define database ################### ##Replace "db_name" with your Database name ## define ("DBNAME","db_name"); ####link to mysql server#### if($link = mysql_connect (HOSTNAME,USERNAME,PWD)) { print "<h1>Connection to MySQL server Successful<br />\n"; } else { die ("<h1>Cannot connect to MySQL server.</h1><br />\n" . mysql_error()); } ####selecting a database#### if (mysql_select_db (DBNAME , $link)) { print "<h2>Connection to Database Successful</h2><br />\n"; } else { die ("<h2>Cannot select database.</h2><br />\n" . mysql_error()); } print "<br /> <div align='center'> <img src='http://www.myliteraturetechlife.com/logo.gif'/> </div> <div align='center'> <a href='http://www.myliteraturetechlife.com.com'>Technical Literature</a></div>"; ?>
Related posts:
















No Comment to “PHP script to test MySQL database Connection”