简体   繁体   中英

MySQL Conventions?

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!

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM