import syeef.com.*;
public class Basics {
//

Basic MySQL Select Query with PHP

This example shows how to do basic MySQL Select Query with PHP:


$server = "localhost"; // MySQL server address
$user = "root"; // MySQL user name
$pass = "1234"; // MySQL user password
$database = "my_database"; // name of your database

$mysql = @mysql_connect($server, $user, $pass)
or die("Could not connect to MySQL server");

@mysql_select_db($database)
or die("Could not connect to MySQL database");

// table: my_table has 2 fields, id(int) and name(varchar)
$query = @mysql_query('SELECT id, name FROM my_table');
while ($row = @mysql_fetch_assoc($query)) {
//read rows from my_table
echo $row['id'] . "\n";
echo $row['name'] . "\n";
}

@mysql_close($mysql); // close MySQL connection
}