Archive for the ‘MySql’ Category

Connect your site with mysql server

June 29, 2009 Leave a comment

Here is a simple [novice type]php script to connect your site with your mysql server.When i start to learning php i use this script to connect my site with my database server.It was so exciting that i can’t tell you.I insert something into a form and that store in database.It was feel like awesome to me.You know the first experience of success.hehehe..

So i give you that.

$db_host = ‘localhost’;
$db_user = ‘root’;
$db_password = ‘triadpass’;
$db_name = ‘db1’;

function connect_db()
global $db_host,$db_user,$db_password,$db_name;

$link = mysql_connect($db_host,$db_user,$db_password);
die(‘Not connected : ‘ . mysql_error());

$db_selected = mysql_select_db($db_name, $link);
if (!$db_selected) {
die (‘Error : ‘ . mysql_error());}
return $link;

Here mentioning that localhost was my mysql server address,username was root, password was triadpass and database was db1 for me not for you.You have your own server address,username,password and database name. After entering your server address,username,password and database name name tihs page as config.php.After naming it,you just have to include this page whenever you need.

Like it
$sql=”select * from table1″;
echo “query successful”;
ok done

Categories: MySql, PHP