binaryWeapon
08-06-2008, 09:55 PM
I'm trying to make a function to check if a certain table exists in the database, and this line is giving me trouble: $tables = mysql_list_tables($db);
$num_tables = mysql_numrows($tables); When I manually hard-code a database name instead of putting the global var $db, it works. What am I doing wrong? I know for a fact that $db is accessible by the function and that it is the correct database name. If it matters, $db was declared inside another function as global $db. The error is this:Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource in /home/nathan/public_html/testzone/database/testnewphp.php on line 16
Table does not exist. Line 16 is the second line in the function, $num_tables = mysql_numrows($tables);
If it matters, the complete code for the function is this:function table($table)
{
$tables = mysql_list_tables($db);
$num_tables = mysql_numrows($tables);
$i = 0;
$exist = 0;
while($i < $num_tables) {
$tablename = mysql_tablename($tables, $i);
if ($tablename==$table) $exist=1;
$i++;
}
if ($exist==0){
die("Table does not exist.");
} else {
$from=$table;
}
}
$num_tables = mysql_numrows($tables); When I manually hard-code a database name instead of putting the global var $db, it works. What am I doing wrong? I know for a fact that $db is accessible by the function and that it is the correct database name. If it matters, $db was declared inside another function as global $db. The error is this:Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource in /home/nathan/public_html/testzone/database/testnewphp.php on line 16
Table does not exist. Line 16 is the second line in the function, $num_tables = mysql_numrows($tables);
If it matters, the complete code for the function is this:function table($table)
{
$tables = mysql_list_tables($db);
$num_tables = mysql_numrows($tables);
$i = 0;
$exist = 0;
while($i < $num_tables) {
$tablename = mysql_tablename($tables, $i);
if ($tablename==$table) $exist=1;
$i++;
}
if ($exist==0){
die("Table does not exist.");
} else {
$from=$table;
}
}