【问题标题】:bind_param difficultiesbind_param 困难
【发布时间】:2012-04-05 03:54:40
【问题描述】:

我遇到了问题,下面的代码没有给我任何结果。但是,如果我取消注释指示的行,并注释掉它可以工作的 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;
}

【问题讨论】:

  • 不要引用? - 准备好的语句引擎会处理所有这些。它应该只是... league_id = ?

标签: php mysql mysqli


【解决方案1】:

函数bool mysqli_stmt::bind_param(字符串$types,混合&$var1[,混合&$...])

接受以下 $types

类型规范字符

人物描述

i 对应的变量具有整数类型

d 对应变量的类型为 double

对应的变量是字符串类型

b 对应的变量是一个 blob,会以数据包的形式发送

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

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

编码愉快!!

【讨论】:

    猜你喜欢
    • 2013-03-14
    • 2019-08-07
    • 2016-12-24
    • 2019-07-16
    • 2021-03-09
    • 2017-04-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多