简体   繁体   English

我只是坚持mysql_ *函数用于简单的mysql_num_rows(),并使用PDO进行更大的查询?

[英]Shoud I just stick to mysql_* functions for simple mysql_num_rows(), and use PDO for bigger queries?

I am converting all my queries to PDO but I am wondering if I should leave "simple" queries as mysql_* functions, like this one: 我正在将我的所有查询转换为PDO,但我想知道是否应该将“简单”查询保留为mysql_ *函数,如下所示:

echo mysql_num_rows(mysql_query("SELECT id FROM users WHERE user_id='$user_id'"))

What I mean is that it just takes one line of code, where as if I use PDO, it would take 4 lines to write. 我的意思是它只需要一行代码,就像我使用PDO一样,它需要4行才能写入。 The sole purpose of this query is to count the rows and echo the result. 此查询的唯一目的是计算行并回显结果。

Should I stick to mysql_* for that kind of small query? 对于那种小型查询,我应该坚持使用mysql_ *吗? Also, note that in my script, there are 10 other queries like this one. 另请注意,在我的脚本中,还有其他10个查询,例如此类查询。

Thanks in advance 提前致谢

Personally I'd convert them all. 就个人而言,我会将它们全部转换。 The main reason I say that is because you will have 2 connections to the DB server for each request. 我说的主要原因是因为每个请求都有2个连接到数据库服务器的连接。 1 for the old mysql_ functions and 1 for PDO. 1表示旧的mysql_函数,1表示PDO。 Not a huge deal but if your site is/gets very large, its just more memory and overhead which you don't need. 没有什么大不了的,但是如果你的网站变得非常大,那么它就是你不需要的更多内存和开销。 If you get overloaded, instead of having say 500 connections to the MySQL server, you have now raised this to 1000 which means more memory and more threads and pushes you closer to your resource limits when it is unnecessary. 如果你超载,而不是说与MySQL服务器有500个连接,你现在已经将它提高到1000,这意味着更多的内存和更多的线程,并在没有必要的情况下推动你更接近你的资源限制。

I can also see the potential for future developers other than yourself seeing the usage of both and not understanding the reasoning for using one or the other in a particular case. 我还可以看到未来开发人员的潜力,除了你自己看到两者的用法,而不理解在特定情况下使用其中一个或另一个的推理。 This may not be an issue though if the code is and always will be yours to manage. 这可能不是问题,但如果代码是并且始终是您的管理。

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

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