php – 将$item = mysql_fetch_assoc($stmt)更改为预准备语句样式

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了php – 将$item = mysql_fetch_assoc($stmt)更改为预准备语句样式脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
这段代码有效,但我想弄清楚如何更改$rose = mysql_fetch_assoc($stmt);部分为“预备声明风格”.谁知道

$rose_id = $_GET['rose_id'];
  //PRepare the statement
  $stmt = $conn2->prepare("SELECT * From rosename 
            LEFT JOIN roseVARiety ON (rosename.variety_name = rosevariety.variety_name) 
            WHERE rose_id = ?");

            //bind the parameters
  $stmt->bind_param("i",$rose_id);

  //$sql = MysqL_query($query,$conn);
  $stmt->execute();

  //was there a good response?
  if ($stmt) {

    $rose = MysqL_fetch_assoc($stmt);

    //echo out rose information
    echo "<h1>".$rose['latin_name']."</h1>";
    echo "<h2>".$rose['common_name']."</h2>";

解决方法

如果使用PDO:

$rose = $stmt->fetch(PDO::FETCH_ASSOC);

http://www.php.net/manual/en/pdostatement.fetch.php

如果使用MysqLi:

$result = $stmt->get_result();
$rose = $result->fetch_assoc();

http://www.php.net/manual/en/mysqli-stmt.get-result.php
http://php.net/manual/en/mysqli-result.fetch-assoc.php

脚本宝典总结

以上是脚本宝典为你收集整理的php – 将$item = mysql_fetch_assoc($stmt)更改为预准备语句样式全部内容,希望文章能够帮你解决php – 将$item = mysql_fetch_assoc($stmt)更改为预准备语句样式所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。