加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – Mysqli准备语句绑定顺序BY

发布时间:2020-12-13 13:48:39 所属栏目:PHP教程 来源:网络整理
导读:我对 mysqli_stmt prepare函数有一个小问题.这是我的查询: $params = array( "sisi","some_string",5000,"date_added DESC");$sql = "SELECT * FROM scenes WHERE scene_title LIKE ? AND scene_id ? ORDER BY ? LIMIT ?"; 现在当我将params绑定到这样的数
我对 mysqli_stmt prepare函数有一个小问题.这是我的查询:
$params = array(
    "sisi","some_string",5000,"date_added DESC"
);

$sql = "SELECT *
        FROM scenes
        WHERE scene_title LIKE ?
        AND scene_id > ?
        ORDER BY ?
        LIMIT ?";

现在当我将params绑定到这样的数组时(我有一个有效的mysqli_stmt对象实例化):

call_user_func_array(array($this->mysql_stmt,'bind_param'),$params);

订单没有绑定.我在php.net上阅读(http://ca3.php.net/manual/en/mysqli.prepare.php)

The markers are legal only in certain
places in SQL statements. For example,
they are allowed in the VALUES() list
of an INSERT statement (to specify
column values for a row),or in a
comparison with a column in a WHERE
clause to specify a comparison value.

However,they are not allowed for
identifiers (such as table or column
names),in the select list that names
the columns to be returned by a SELECT
statement,or to specify both operands
of a binary operator such as the =
equal sign.

有没有办法绕过这个或者我将不得不使用mysql_real_escape_char()作为ORDER BY子句?

由于您找到了php.net链接状态,因此不能将绑定变量用于标识符.你需要一个解决方法. mysql_real_escape_char肯定是单向的.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读