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

Connect To MySQL Database

$yourfield = "FirstName";

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

$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