简体   繁体   English

MySQL约定?

[英]MySQL Conventions?

I just moved my website to a new server (Shared to VPS) 我刚刚将我的网站移动到新服务器(共享到VPS)

I expected errors, and the only error that is really puzzling me is this SQL statement. 我期待错误,唯一令我困惑的错误就是这个SQL语句。

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 ,它会返回

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更改,而mySQL完全搞砸了。 DNS has finally updated! DNS终于更新了!

Try to find out what error you get by adding or die like this: 尝试通过添加or die来找出你得到的错误:

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数据库,请参阅以下函数:

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: 如果您的MySQL数据库中包含索引损坏的表,则可能会收到错误消息:

 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://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.linuxquestions.org/questions/linux-software-2/mysql-crash-on-startup-incorrect-file-format-h​​ost-464422/

http://www.devcomments.com/SQL-Error-incorrect-file-format-to138833.htm 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: 您需要将MySQL结果资源传递给mysql_num_rows如下所示:

$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. 但在这种情况下,表名称不需要引用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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