如何将 PDO 转换为 mysqli?
问题描述
我有一个登录屏幕,用户可以在其中输入用户名和密码.我设法使用 PDO 连接到数据库,但我必须将其更改为 mysqli.有人能帮我把它转换成mysqli吗?提前致谢.
I have a login screen in which the user inputs their username and password. I managed to connect to the database using PDO but I have to change it to mysqli. Could someone please help me convert it to mysqli. Thanks in advance.
PDO:
Mysqli(这是我尝试过的)
Mysqli (This is what I have tried)
运行Mysqli代码时出错:
Error when running Mysqli code:
更新:
Mysqli
推荐答案
你的问题在这里:
prepare
需要一个字符串,mysqli_query
是一个执行查询的过程函数.去掉那个.此外,使用 mysqli,您需要先绑定参数,而不是将它们传递给 execute()
.
prepare
expects a string, mysqli_query
is a procedural function which executes the query. Remove that. Additionally, with mysqli you need to bind the parameters first, not pass them to execute()
.
以下是手册的相关部分:
Here's the relevant sections of the manual:
http://php.net/manual/en/mysqli.prepare.php
http://php.net/manual/en/mysqli-stmt.bind-param.php
http://php.net/manual/en/mysqli-stmt.执行.php
这篇关于如何将 PDO 转换为 mysqli?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!