MySQLi 使用先前获取的 $variable 的多个预准备语句

MySQLi multiple prepared statements using previous fetched $variable

提问人:Pietro di Caprio 提问时间:11/20/2014 更新时间:11/20/2014 访问量:102

问:

$stmt = $mysqli->prepare("SELECT id,name,master,level,exp FROM player.guild ORDER BY exp DESC");
$stmt->execute();
$stmt->bind_result($id, $name, $master, $level, $exp);
$stmt->fetch();
$guildnum = $stmt->num_rows;
$stmt->store_result();
$stmt->close();

$stmt2 = $mysqli->prepare("SELECT id,login FROM account.account WHERE id=?");
$stmt2->bind_param("i", $master);
$stmt2->execute();
$stmt2->bind_result($boss_id, $boss_name);
$stmt2->store_result();
$stmt2->close();

$stmt3 = $mysqli->prepare("SELECT empire FROM player.player_index WHERE id=?");
$stmt3->bind_param("i", $boss_id);
$stmt3->execute();
$stmt3->bind_result($empire);
$stmt3->store_result();
$stmt3->close();      

$stm 2 和 $stm 3 未返回结果。

解释代码

$stm获取一些详细信息并将它们存储到$variables

$stm 2 使用变量 $master 来获取 “id” 和 “login” 并将它们存储到其他变量中

$stm 3 使用 $boss_id(由 $stm 2 存储)来获取和设置变量 $empire

解释代码

谁能帮我?

问候。

php mysql mysqli 语句

评论

0赞 vaso123 11/20/2014
倾倒.里面有什么东西吗?$master
0赞 Pietro di Caprio 11/20/2014
$master为空 **** 编辑 **** $master显示 1,是正确的。
0赞 Pietro di Caprio 11/20/2014
尝试过但没有错误..printf("Error2: %s.\n", $stmt2->error);
0赞 vaso123 11/20/2014
你有id 1的记录吗?account.account

答:

0赞 Gerardo Charles Rojas Vega 11/20/2014 #1

因此,如果一切正确,只需获取值 (bind_result)

    $stmt = $mysqli->prepare("SELECT id,name,master,level,exp FROM player.guild ORDER BY exp DESC");
    $stmt->execute();
    $stmt->bind_result($id, $name, $master, $level, $exp);
    $stmt->fetch(); //fetch values
    $guildnum = $stmt->num_rows;
    $stmt->store_result();
    $stmt->close();

    $stmt2 = $mysqli->prepare("SELECT id,login FROM account.account WHERE id=?");
    $stmt2->bind_param("i", $master);
    $stmt2->execute();
    $stmt2->bind_result($boss_id, $boss_name);
    $stmt2->fetch(); //fetch values
    $stmt2->close();

    $stmt3 = $mysqli->prepare("SELECT empire FROM player.player_index WHERE id=?");
    $stmt3->bind_param("i", $boss_id);
    $stmt3->execute();
    $stmt3->bind_result($empire);
    $stmt3->fetch(); //fetch values
    $stmt3->close();

评论

0赞 Gerardo Charles Rojas Vega 11/20/2014
对不起,我忘了添加评论:$stmt->fetch();