?? PDO或mySQLi [英] Php? PDO or mySQLi
问题描述
只需编写一个PHP网站并使用mySqli进行数据库连接即可.真的很喜欢它,因为我可以使用Prepare语句,然后执行$result = $stmt->get_result();
将结果加载到关联的数组中.但是,认为最好是时候将几个页面和数据库上传到托管站点以测试速度,从而发现它不支持$stmt->get_result();
命令,需要使用主机不支持的mysqlnd驱动程序.
Just writing a PHP website and using mySqli for my database connectivity. Really enjoying it as I can use Prepare statements and then do a $result = $stmt->get_result();
which loads results into an associated array. However, thought it best be time to upload a few pages and the DB to hosting site to test speed and such to find that it does not support the $stmt->get_result();
command, having it needing to use the mysqlnd driver which my host does not support.
也没有这个问题,很多主机提供商也没有.现在,当我启动网站时,我回顾了一些旧的PHP代码,显然我过去使用的常规mySql代码已经过时了,并在互联网上被告知要使用mySQLi来代替,只是发现对此的支持下降到了. ?!这样就可以看到,那么要使用的最佳mySql连接是什么?
Looking into this nor does many host providers either. Now when I started the website I looked back at some of my old PHP code and apparently the normal mySql code that I used to use has become obsolete and was told on the internet to use mySQLi instead only to find that support for this is dropping to?! so it would see, so what is the best mySql connectivity to use?
推荐答案
我根本不会使用任何旧的mysql
连接器.由于存在巨大的安全漏洞,因此不推荐使用它们.至于是否要使用通过mysqli
或PDO
使用的准备好的语句,则由您选择.他们俩都很安全.只要您使用预准备的语句并且不依赖于转义变量(这是一个巨大的痛苦并且容易犯错,因此不那么安全),mysqli
就可以了.
I would not use any old mysql
connectors at all. They are deprecated due to huge gaping security holes. As for whether you want to use prepared statements using mysqli
or PDO
, that is a matter of choice; they both are pretty secure. mysqli
is good as long as you use prepared statements and don't rely on escaping your variables (which is a huge pain and easy to make a mistake, so therefore not as secure).
使用PDO
的优点在于,在不同的数据库类型之间移动更容易(例如,如果您要使用Oracle或SQL Server或PostreSQL),更容易进行转换,并且如果使用PDO
,则功能更强大您喜欢与班级一起工作.在此站点上,您通常会找到更多喜欢PDO
的人.
The advantages of using PDO
is that is easier to move between different database types (e.g. if you want to work with Oracle or SQL Server or PostreSQL) it is easier to make the transition, and it is far more powerful if you like to work with classes. On this site you will generally find more people who prefer PDO
.
还支持mysqlnd
吗?请参阅官方网站上的以下文档:
Also as for support for mysqlnd
? See below documentation from the official site:
PHP 5.4的默认值为mysqlnd
PHP 5.4 has mysqlnd as default
从PHP 5.4开始,mysqlnd库是php.net的编译时默认值 所有PHP MySQL扩展.另外,Windows团队php.net正在使用 自mysqlnd成为mysqlnd以来的正式PHP Windows发行版 在PHP 5.3中可用
As of PHP 5.4, the mysqlnd library is a php.net compile time default to all PHP MySQL extensions. Also, the php.net Windows team is using mysqlnd for the official PHP Windows distribution since mysqlnd became available in PHP 5.3
换句话说,那些网络托管服务提供商落后于时代.您可能想寻找一个更好的产品.
In other words, those web host providers are behind the times. You might want to look for a better one.
这篇关于?? PDO或mySQLi的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!