Create table and install data
<?
define("DBName","test");
define("HostName","localhost");
define("UserName","root");
define("Password","");
if(!mysql_connect(HostName,UserName,Password)){
echo "Cannot get connected to the database ".DBName."!<br>";
echo mysql_error();
exit;
}
mysql_select_db(DBName);
// Creating the t table. If it already exists,
// "@" overrides the error message
@mysql_query("create table t(id int, a double)");
// Inserting 10 records into the table
for($i=0; $i<10; $i++){
$id=time();
mysql_query("insert into t(id, a) values($id, '$i')");
}
// Outputting all records
$r=mysql_query("select * from t");
for($i=0; $i<mysql_num_rows($r); $i++) {
$f=mysql_fetch_array($r);
echo "$f[id] -> $f[a]<br>\n";
}
?>
Related examples in the same category