gpt4 book ai didi

php - bind_param 困难

转载 作者:行者123 更新时间:2023-11-29 02:32:57 28 4
gpt4 key购买 nike

我遇到了以下代码没有结果的问题。但是,如果我取消注释掉指定的行,并注释掉它起作用的 bind_param 行,但这不是破坏了 mysqli 的目的吗?我的 var_dump 给了我的字符串(1)“1”

function teams($mysqli, $league_id) {
echo 'league id = ' . var_dump($league_id);
$sql = "SELECT team_id, team_name FROM teams where league_id='?'";
// $sql = "SELECT team_id, team_name FROM teams where league_id='".$league_id."'";
$stmt = $mysqli->prepare($sql);
$stmt->bind_param('i', $league_id);
$stmt->execute();
$stmt->bind_result($col1, $col2);
while($stmt->fetch()) {
$results[] = array(
'team_id' => $col1,
'team_name' => $col2
);
}
$stmt->close();
var_dump($results);
return $results;
}

最佳答案

函数 bool mysqli_stmt::bind_param ( string $types , mixed &$var1 [, mixed &$... ] )

接受以下 $types

类型规范字符

人物描述

i对应的变量类型为整型

d对应的变量是double类型

对应的变量的类型是string

b对应的变量是一个blob,会打包发送

您将 $types 指定为 'i' 并将值作为单引号中的字符串给出。删除引号并尝试将 $league_id 转换为 int 值。

http://php.net/manual/en/mysqli-stmt.bind-param.php

编码愉快!!

关于php - bind_param 困难,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10022457/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com