sponsor

Sunday, July 22, 2007

How To Connect PHP - MySQL

In this post, I will explain you about PHP and MySQL. You can use PHP with MySQL database. You only need a simple script to connect PHP- MySQL.
1. mysql_connect() -- Open a connection to a MySQL Server
This function need several parameters. For example :
mysql_connect("localhost","root","12345")
notes : localhost --> the mysql server name
root --> the mysql username
12345 --> the mysql password

example : $link = mysql_connect("localhost", "mysql_user", "mysql_password")
or die("Could not connect");

2. mysql_select_db() --> Select a MySQL database
You need database name for this function
example : mysql_select_db("mysql")
notes : mysql is the database name is mysql database

3. mysql_query() --> Send a MySQL query
example : $result = mysql_query("SELECT * WHERE user='jhon'")
or die("Invalid query");
notes : SELECT * WHERE user='jhon' is query for mysql.