Sunday, February 8, 2009

Connecting to MySQL Database in 5 Simple steps using php


\<\?php
//Step 1: connecting to database server
$connection = mysql_connect("localhost","root","");
//("server","user","password")


//Step 2: selecting a database
$sel_database = mysql_select_db("database_name"); //("name of the database that you want to connect to")


//Setp 3: doing the query
$query = "SELECT * FROM table1";
$result = mysql_query($query,$connection);


//Step 4: presenting retrieved data
while ($row = mysql_fetch_array($result)){
foreach($row as $value){
echo $value."\t";
}
echo "
";
}


//Step 5: closing the connection
mysql_close($connection);
?>

No comments:

Post a Comment