Monday, April 11, 2011

PHP Tutorials, script to connect to the MySql database

This script is used for connection to the database MySQL. The first is that we must know the host, username, and password to connect to MySql. By default host is "localhost" and the username is "root". For the password depends on when you install the program to your database. such appserv, xampp, wampp. just this php script to connect to the database.  

<? php 
mysql_connect ("localhost", "root", "password"); 
mysql_select_db ("MyDatabase"); 
?>  

script above for a password can be changed according to the password for your database. and "MyDatabase" above is the name of the database that you created with MySQL or phpMyAdmin. To try the script above we can write like this. 

<? php  
$query = mysql_connect ("localhost", "root", "password");  
mysql_select_db ("MyDatabase"); 
if ($ query)  

 echo "successfully connect to database "; 
}  
else 
{ 
echo "can not successfully connect to the database "; 
}
?>  
then save this file with a name like" connect.php ". ooo you can write this in notepad, edit + +, or Dreamweaver. Good luck.   By Ardian