dourong9253 2017-06-19 05:15
浏览 33

Prepared语句将参数视为列名

Edit: I think the bug is in a different part of the code. Apparently, when testing prepared statements in phpmyadmin, phpmyadmin simply performs a search-replace on the parameters rather than actually using a prepared statement in PDO.

The PHP login script which I am working on uses mysqli to access a database.

A key part of the script queries the users table to return the password hash.

$stmt = $mysqli->prepare("SELECT password FROM users WHERE username = ?");
$stmt->bind_param("s", $_POST["username"]);
$stmt->execute();
$stmt->bind_result($hash);

I have a row in the table with itcha2 as the username, but when I pass itcha2 as the username to the script, it returns no rows.

When I enter the query into phpmyadmin , SELECT * FROM users WHERE username = :user, binding itcha2 as :user, phpmyadmin returns the error #1054 - Unknown column 'itcha2' in 'where clause'

As I understand it, a parameter from a prepared statement should never be interpreted as a column name.

What is going on?

Any help is most sincerely appreciated.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 有偿求跨组件数据流路径图
    • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
    • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
    • ¥15 CSAPPattacklab
    • ¥15 一直显示正在等待HID—ISP
    • ¥15 Python turtle 画图
    • ¥15 关于大棚监测的pcb板设计
    • ¥15 stm32开发clion时遇到的编译问题
    • ¥15 lna设计 源简并电感型共源放大器
    • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)