Jump to content

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result


clankill3r

Recommended Posts

hi, i get this error:

 

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\Doeke\kamertweets\cms\lib.php on line 115

 

line 115 is this line:

if(!mysql_fetch_array($rs))

 

(I'm trying to check if a database exists.)

 

function table_exists($dbName, $tableName)
{ 	
$sql ='SHOW TABLES WHERE Tables_in_' . dbName . ' = \'' . $tableName . '\'';
$rs = mysql_query($sql);

if(!mysql_fetch_array($rs))
	return FALSE;
else
	return TRUE;
}

that leaves me with this error:

 

Query: SHOW TABLES WHERE Tables_in_dbName = 'fleuragemapvv'

Failed with error: Unknown column 'Tables_in_dbName' in 'where clause'

 

I only don't want a error, i just want it to return false.

If you just need to know if a database exists, you'll be able to tell when you call mysql_select_db. It will return FALSE if the specified database doesn't exist.

That isn't what you said in the OP but this is what you need. Then just check it with mysql_num_rows() to see if any records were returned. IF however, you're attempting to see if the table exists before trying to create a table, you can use the CREATE table IF NOT EXISTS syntax.

 

SHOW TABLES FROM `database` LIKE 'table_name'

the link is very unclear to me.

Sorry i said database in the OP, i meant table (it's like 35 degrees in my room...).

 

Now i got:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\Doeke\kamertweets\cms\lib.php on line 117

function table_exists($dbName, $tableName)
{ 	
$sql ='SHOW TABLES IN $dbName WHERE $tableName = $tableName';

$rs = mysql_query($sql);

if(!mysql_fetch_array($rs))
	return FALSE;
else
	return TRUE;
}

 

as for the create table if not exists

 

I don't get a error but my database stays empty

 

$sql = "CREATE table IF NOT EXISTS $twitter_id
{
	id int,
	tweet varchar(200),
	reply_to int,
	date datetime	
}";
// execute query
mysql_query($sql, $db);

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.