I am new php learner and mysql and trying to creating pages for my project. I try to create it but fails to so. also i would like to enter docfile field that matches the record trying to entered into database.please help me to do so.
thank you
Printable View
I am new php learner and mysql and trying to creating pages for my project. I try to create it but fails to so. also i would like to enter docfile field that matches the record trying to entered into database.please help me to do so.
thank you
You can try mysqldump with the dump table with the add-drop option and inside.sql file
Quote:
The syntax for mysqldump : mysqldump --add-drop-table dbname tablename
also
$check = mysql_query ("SELECT * FROM `tableName` LIMIT 0,1"); /* >>limit<< is just to make it faster in case the db is huge */
if ($check){
// query was legal and could be executed by the server
}else{
// something wrong, so:
// create the table
}
try this code
Quote:
<?php
function db_connect() {
$host = 'localhost';
$user = 'root';
$pass = '273568';
$line = @mysql_connect($host, $user, $pass);
return $line;
}
function mysql_is_table($db,$tbl)
{
$line = db_connect();
$tables = array();
@mysql_select_db($db);
$q = @mysql_query("SHOW TABLES", $line);
while ($r = @mysql_fetch_array($q)) { $tables[] = $r[0]; }
@mysql_free_result($q);
@mysql_close($line);
if (in_array($tbl, $tables)) { return TRUE; }
else { return FALSE; }
}
function mysql_is_database($db)
{
$line = db_connect();
$databases = array();
$q = @mysql_query("SHOW DATABASES LIKE $db", $line);
while ($r = @mysql_fetch_array($q)) { $databases[] = $r[0]; }
@mysql_free_result($q);
@mysql_close($line);
if (in_array($db, $databases)) { return TRUE; }
else { return FALSE; }
}
// example usage
$newdbName = 'testDatabase';
$newdbTable = 'testTable';
if (mysql_is_database($newdbName)) {
echo 'Yes the news database is present';
if(mysql_is_table($newdbName,$newdbTable) {
echo 'Table is present';
} else {
mysql_query("CREATE TABLE " .$newdbTable);
if(mysql_error()) {
echo mysql_error();
//do some error trapping
}
}
} else {
mysql_query("CREATE DATABASE " .$newdbName);
if(mysql_error()) {
echo mysql_error();
//do some error trapping
}
}