clankill3r Posted June 4, 2011 Share Posted June 4, 2011 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; } Quote Link to comment https://forums.phpfreaks.com/topic/238393-warning-mysql_fetch_array-supplied-argument-is-not-a-valid-mysql-result/ Share on other sites More sharing options...
Pikachu2000 Posted June 4, 2011 Share Posted June 4, 2011 $rs = mysql_query($sql) or die( "<br>Query: $sql<br>Failed with error: " . mysql_error() ); Quote Link to comment https://forums.phpfreaks.com/topic/238393-warning-mysql_fetch_array-supplied-argument-is-not-a-valid-mysql-result/#findComment-1225090 Share on other sites More sharing options...
fugix Posted June 4, 2011 Share Posted June 4, 2011 for correct syntax view http://dev.mysql.com/doc/refman/5.0/en/show-tables.html Quote Link to comment https://forums.phpfreaks.com/topic/238393-warning-mysql_fetch_array-supplied-argument-is-not-a-valid-mysql-result/#findComment-1225096 Share on other sites More sharing options...
clankill3r Posted June 4, 2011 Author Share Posted June 4, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/238393-warning-mysql_fetch_array-supplied-argument-is-not-a-valid-mysql-result/#findComment-1225100 Share on other sites More sharing options...
Pikachu2000 Posted June 4, 2011 Share Posted June 4, 2011 Using the wrong query syntax it isn't going to work at all, that's why I posted the code to show the error. Quote Link to comment https://forums.phpfreaks.com/topic/238393-warning-mysql_fetch_array-supplied-argument-is-not-a-valid-mysql-result/#findComment-1225103 Share on other sites More sharing options...
Pikachu2000 Posted June 4, 2011 Share Posted June 4, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/238393-warning-mysql_fetch_array-supplied-argument-is-not-a-valid-mysql-result/#findComment-1225104 Share on other sites More sharing options...
clankill3r Posted June 4, 2011 Author Share Posted June 4, 2011 I need to check if a table in a database exists, not the database itself. Quote Link to comment https://forums.phpfreaks.com/topic/238393-warning-mysql_fetch_array-supplied-argument-is-not-a-valid-mysql-result/#findComment-1225106 Share on other sites More sharing options...
fugix Posted June 4, 2011 Share Posted June 4, 2011 did you look at the link I posted for correct sytnax? $sql ='SHOW TABLES IN db_name WHERE 'something' = 'something'''; Quote Link to comment https://forums.phpfreaks.com/topic/238393-warning-mysql_fetch_array-supplied-argument-is-not-a-valid-mysql-result/#findComment-1225107 Share on other sites More sharing options...
Pikachu2000 Posted June 4, 2011 Share Posted June 4, 2011 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' Quote Link to comment https://forums.phpfreaks.com/topic/238393-warning-mysql_fetch_array-supplied-argument-is-not-a-valid-mysql-result/#findComment-1225110 Share on other sites More sharing options...
clankill3r Posted June 4, 2011 Author Share Posted June 4, 2011 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); Quote Link to comment https://forums.phpfreaks.com/topic/238393-warning-mysql_fetch_array-supplied-argument-is-not-a-valid-mysql-result/#findComment-1225115 Share on other sites More sharing options...
clankill3r Posted June 4, 2011 Author Share Posted June 4, 2011 i got { instand of ( It works now. I only deleted my whole database by accident Quote Link to comment https://forums.phpfreaks.com/topic/238393-warning-mysql_fetch_array-supplied-argument-is-not-a-valid-mysql-result/#findComment-1225117 Share on other sites More sharing options...
fugix Posted June 4, 2011 Share Posted June 4, 2011 i got { instand of ( It works now. I only deleted my whole database by accident dang... :'( Quote Link to comment https://forums.phpfreaks.com/topic/238393-warning-mysql_fetch_array-supplied-argument-is-not-a-valid-mysql-result/#findComment-1225118 Share on other sites More sharing options...
Pikachu2000 Posted June 4, 2011 Share Posted June 4, 2011 Please don't tell me you're creating a new table for every id . . . Quote Link to comment https://forums.phpfreaks.com/topic/238393-warning-mysql_fetch_array-supplied-argument-is-not-a-valid-mysql-result/#findComment-1225119 Share on other sites More sharing options...
clankill3r Posted June 4, 2011 Author Share Posted June 4, 2011 no i have 152 users (dutch reprsentetives), some of them have more then 5000 posts. Every dutch representetive has it own table. is that bad? at least it works! Quote Link to comment https://forums.phpfreaks.com/topic/238393-warning-mysql_fetch_array-supplied-argument-is-not-a-valid-mysql-result/#findComment-1225225 Share on other sites More sharing options...
Pikachu2000 Posted June 4, 2011 Share Posted June 4, 2011 That's horrible database design. There's absolutely no reason to have a table for each user. Quote Link to comment https://forums.phpfreaks.com/topic/238393-warning-mysql_fetch_array-supplied-argument-is-not-a-valid-mysql-result/#findComment-1225227 Share on other sites More sharing options...
fugix Posted June 4, 2011 Share Posted June 4, 2011 Don't settle with "it just works". There is no logic to what you set doing. Instead of creating a table for each user. Create one table and assign each user a unique key. Quote Link to comment https://forums.phpfreaks.com/topic/238393-warning-mysql_fetch_array-supplied-argument-is-not-a-valid-mysql-result/#findComment-1225245 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.