Connect To MySQL Database : MySQL Connection « MySQL Database « PHP






Connect To MySQL Database



<?php
//
$hostname="mysql153.secureserver.net";
$username="java2s";
$password="password";
$dbname="java2s";
$usertable="Employee";
$yourfield = "FirstName";

mysql_connect($hostname,$username, $password) OR DIE ("Unable to connect to database! Please try again later.");
mysql_select_db($dbname);

$query = "SELECT * FROM $usertable";
$result = mysql_query($query);
if($result) {
    while($row = mysql_fetch_array($result)){
        $name = $row["$yourfield"];
        echo "Name: ".$name;
    }
}
?>
           
       








Related examples in the same category

1.Listing the Databases Available in a Connection
2.Connect to MySQL
3.Opening a Connection and Selecting a Database