tags:

views:

72

answers:

2
+4  Q: 

MySQL Conventions?

Hi There,

I just moved my website to a new server (Shared to VPS)

I expected errors, and the only error that is really puzzling me is this SQL statement.

echo mysql_query("SELECT COUNT(*) FROM users_online_now")

This returns nothing! And if I try the mysql_num_rows, it returns

mysql_num_rows(): supplied argument is not a valid MySQL result resource..

If I query another table though eg:

echo mysql_query("SELECT COUNT(*) FROM users")

It works fine.

I am guessing it's something to do with the naming of the table? It worked fine on my previous host, is there some setting I should modify?

Update: Figured out. The server is still going thru DNS changes, and the mySQL is completely messed up. DNS has finally updated!

+6  A: 

Try to find out what error you get by adding or die like this:

mysql_query("SELECT COUNT(*) FROM `users_online_now`") or die(mysql_error());

Also make sure that you have already connected to mysql database successfully, see these functions for that:

mysql_connect
mysql_select_db

Note: In names you should use backtick character (`) rather than single quote.

Update:

If you have a MySQL Database that has a table with a damaged Index, you may get an error:

 Incorrect file format [table name]

Here is the possible solution.

.

More threads on the problem:

http://forums.mysql.com/read.php?21,18436,18436

http://www.linuxquestions.org/questions/linux-software-2/mysql-crash-on-startup-incorrect-file-format-host-464422/

http://www.devcomments.com/SQL-Error-incorrect-file-format-to138833.htm

Sarfraz
I'm connected normally, and that mysql_error() returned:Incorrect file format 'users_online_now'
Moe
@Moe: See my updated answer please.
Sarfraz
Repair still didn't work! This is very odd.
Moe
@Moe: It seems that the database is not repairable. Do you have the backup of it somewhere?
Sarfraz
I do have a backup. I'll try re-creating it.
Moe
+1  A: 

You need to pass the MySQL result resource to mysql_num_rows like so:

$result = mysql_query("SELECT COUNT(*) FROM `users_online_now`");
echo mysql_num_rows($result);

You should also use ` for table names if they need to be quoted. But in this case the table name does not need to be quoted.

Gumbo