Hey, I'm working on a College project that means you have to re-do the database each time you work on your assignment. So, what I'm hoping to create is a file called "sql_connect.php" which will check if the table is there, if not.. It will run the function that creates it. Here is my code:
<?php
DEFINE ('DB_USER', 'USERNAME');
DEFINE ('DB_PASSWORD', 'PASSWORD');
DEFINE ('DB_HOST', 'localhost');
DEFINE ('DB_NAME', 'TABLE');
// make the connection
$dbc = @mysql_connect (DB_HOST, DB_USER, DB_PASSWORD) OR die ('');
// select the database
$tbc = @mysql_select_db (DB_NAME) OR die ('fgddffdfdfd');
if(!$tbc)
{
sql_insert();
}else{
}
?>
Thanks for any help
<?php
//check table
function checktable($tablename){
return mysql_query("select * from ".$tablename." limit 0,1");
}
$table="table_name_that_want_to_be_check";
if(checktable($table)){
echo"table already created";
}else{
//create table if not exist
mysql_query("CREATE TABLE ".$table." (
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
data VARCHAR(100),
......................
);")
echo "table created"
}
?>
Reputation Points: 10
Solved Threads: 1
Junior Poster in Training
Offline 70 posts
since Mar 2008