php - 为什么 mysqli 绑定(bind)函数不能正确处理我的字符串?

标签 php mysql mysqli prepared-statement

我花了大约一个月的时间才弄清楚如何在 PHP 中使用 session 处理函数。我只有一个问题,bind_param功能使用i获取记录而不是 s .

$stmt = $mysqli->prepare("SELECT data FROM session WHERE  id = ?");
$stmt->bind_param('i', $id);
$stmt->execute();

$id是一个包含数字和字母的 session ID,例如:e5eeire57wjeuewq8w即使我没有此 session 的记录,此查询也会在 num_rows 中返回大约 8 条记录.所以我通过放置 s 解决了这个问题而不是 i在绑定(bind)参数中。

我的问题是,为什么绑定(bind)参数将我的字符串视为整数?为什么即使我有 0 行具有此 ID,它也返回 8 行?

最佳答案

bind_param page 有评论这证实了 Jon 在评论中所说的话

PHP will automatically convert the value behind the scenes to the underlying type corresponding to your binding type string. i.e.:

$var = true;
bind_param('i', $var); // forwarded to Mysql as 1

关于php - 为什么 mysqli 绑定(bind)函数不能正确处理我的字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30057451/

相关文章:

php - mysql多个唯一键与重复键引用

php - 在查询中使用 echo

php - 如何根据数据库表创建html菜单

mysql - 需要简单查询的索引

PHP调用监听脚本持续运行

php - 如何让 mysqli 在 SQL 语句中使用 DELIMITER?

php - 如何在不删除标签的情况下替换 HTML 标签内的空格

php - 无法进入PHP交互模式

mysql - OSX Docker/WordPress/MySQL -- 连接错误 : (1130) Host 'xxx.xxx.xxx.xxx' is not allowed to connect to this MariaDB server

mysql - 有了MySQL临时表,为什么还要Redis?