【问题标题】:Store_result and get_result for statementstore_result 和 get_result for 语句
【发布时间】:2014-04-26 15:08:36
【问题描述】:

当我在 mysqli 库中使用 PHP 中的语句时,在获取和 bind_results 之前,我调用了 store_result。 在我看到带有 fetchArray/object 等方法的 mysqli_result 类之后。 因此,如果我想使用它,我会从 mysqli_stmt 对象调用 get_results 方法...但是如果我在方法 store_result 之前调用它会给我一个“非对象”错误(get_result 返回 false)。 乙:

$s = $stmt->get_result(); //this work

如果我这样做了

$stmt->store_result();
$s = $stmt->get_result(); //this not work, return false

所以我试图了解何时需要使用 store_result 或 get_result(以及正确的方法),但在 Mysql 和 php doc 中我没有发现任何有用的东西。

PS:你能解释一下为什么我应该使用第一个或第二个吗?

【问题讨论】:

    标签: php mysql mysqli


    【解决方案1】:

    尽可能使用 get_result 并在其他地方使用 store_result。

    【讨论】:

    • 你能解释一下为什么我应该使用第一个或第二个吗?谢谢
    • 你明白get_result是做什么的吗?
    • get_result 返回 mysqli_result 对象。我可以使用它为结果执行 fetchArray 或其他方法。我不明白的是,使用 get_result 的方法或使用 store_result 并自己定义 fetchArray 等方法是否是一个好习惯。谢谢你的回答。
    • 是的。坦率地说,get_result 使 mysqli 准备好的语句至少可用。所以,你没有理由避免它。
    • @JeffPuckettII 唯一的选择是 bind_result
    猜你喜欢
    • 2015-10-06
    • 1970-01-01
    • 2012-05-15
    • 1970-01-01
    • 2013-02-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多