Monday, August 20, 2007

Mysql Database 1.

Here i will show you how to handle php with mysql.

Before we start mysql you must read the following topic Database Normalization so that you can handle data properly.

Connection to mysql

// To connect to mysql the mysql_connect() function is called.The mysql_connect function takes three arguments. Server, username, and password.
Example:
* Server - localhost
* Username - admin
* Password - admin123
so the code to connect will be
mysql_connect("localhost", "admin", "admin123") or die(mysql_error());
?>


The "or die(mysql..." code displays an error message in your browser if there is an error!
After establishing a MySQL connection with the code above, you then need to choose which database you will be using with this connection.
For this you need to call the mysql_select_db function.

mysql_connect("localhost", "admin", "admin123") or die(mysql_error());
mysql_select_db("test")or die(mysql_error());
?>

The above code will first connect the local mysql server then select the database test.
Now you are ready for mysql queries from the database test with php.

To be cont...
Copyright Ayon Baidya

No comments:

Post a Comment