SQL

Sunday, 4 March 2012

PHP MySQL Connection Test


Sometime it is necessary to make a test that PHP is working with MySQL.So after installing LAMP Server, try the following code to get the test done :


Click here


Then Write down the following codes:

mysql_connect("localhost", "root", "root") or die(mysql_error());
echo "Connected to MySQL
";
mysql_select_db("database_1.1") or die(mysql_error());
echo "Connected to Database
";

$result = mysql_query("SELECT * FROM Employee");

$row = mysql_fetch_array( $result );
// Print out the contents of the entry 

echo "FirstName: ".$row['first_name'];
echo "Last Name: ".$row['last_name'];


If you run the script from the browser:

localhost/test.php

You will see something like :



Post a Comment