BackNext

mySQL

Now that we have a source of data, and a script to put the data into a database, and even a way to test the database to see that the data is entered correctly and can be accessed, we need to create the database. First a user needs to be created to access the database. The user needs to have a logon password. Then the database can be created. Here is a PHP script to create the database.

<?php
// Setup variables for database

$host = "localhost" ; //default you may have to change this
$user = "user" ; //your database user name
$pass = "password" ; //your database password
$db = "db_Name" ; //name of your database
$dbf = "table_name"; //name of database field

// connect to the database server

$con = mysql_connect("$host","$user","$pass");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

// Create database

if (mysql_query("CREATE DATABASE $db",$con))
{
echo "Database created";
}
else
{
echo "Error creating database: " . mysql_error();
}
/
// Create table in my_db database

mysql_select_db("$db", $con);
$sql = "CREATE TABLE $dbf
(
dataID int NOT NULL AUTO_INCREMENT,
PRIMARY KEY(dataID),
tm datetime,
t1 float,
t2 float,
dp float,
rh float,
bp float,
wdspd float,
gst float,
wddir tinytext,
rn float,
drn float,
rnrt,
)";



mysql_query($sql,$con);

mysql_close($con);
?>

BackNext