It took me like a month to figure out how make a session handler function work in PHP. I only had one problem, the bind_param
function using i
to fetch records instead of s
.
我用了一个月的时间来弄清楚如何使会话处理函数在PHP中运行。我只有一个问题,bind_param函数使用i来获取记录而不是s。
$stmt = $mysqli->prepare("SELECT data FROM session WHERE id = ?");
$stmt->bind_param('i', $id);
$stmt->execute();
This $id
is a session id with contains numbers and letters like: e5eeire57wjeuewq8w
Even if I have no records with this session, this query returns about 8 records in num_rows
. So I solved this by putting a s
instead of i
in bind param.
此$ id是一个会话ID,包含数字和字母,如:e5eeire57wjeuewq8w即使我没有此会话的记录,此查询返回num_rows中的大约8条记录。所以我通过在bind param中放入s而不是i来解决这个问题。
My question here is, why does bind param treat my string like an integer? Why does it return 8 rows even if I had 0 rows with this id?
我的问题是,为什么bind param将我的字符串视为整数?为什么它返回8行,即使我有0行这个id?
1 个解决方案
#1
There's a comment on the bind_param page that confirms what Jon said in comments
bind_param页面上有一条评论,证实了Jon在评论中所说的内容
PHP will automatically convert the value behind the scenes to the underlying type corresponding to your binding type string. i.e.:
PHP会自动将幕后的值转换为与绑定类型字符串对应的基础类型。即:
$var = true;
bind_param('i', $var); // forwarded to Mysql as 1
#1
There's a comment on the bind_param page that confirms what Jon said in comments
bind_param页面上有一条评论,证实了Jon在评论中所说的内容
PHP will automatically convert the value behind the scenes to the underlying type corresponding to your binding type string. i.e.:
PHP会自动将幕后的值转换为与绑定类型字符串对应的基础类型。即:
$var = true;
bind_param('i', $var); // forwarded to Mysql as 1