【问题标题】:PHP - Test if there's a MySQLi outputPHP - 测试是否有 MySQLi 输出
【发布时间】:2014-05-16 04:59:38
【问题描述】:

我想要一个测试是否有mysql输出的php脚本,目前我有以下代码:

$mysqli = new mysqli('localhost', 'root', NULL, 'forum');
$query = "SELECT id,titel,auteur,datum FROM topics WHERE categorieid=$categorieid ORDER by id DESC";

为了测试结果,我没有工作代码,所以在这里发布其余部分无济于事

我想要一个 if 语句,如果查询返回结果 echo this,否则 echo this

谁能帮我解决这个问题?谢谢!

提醒:它必须是 MySQLi,使用 MySQL 就像 PHP 所说的那样“过时”

编辑:

if ($stmt = $mysqli->prepare($query)) {
$stmt->execute();
$stmt->bind_result($id,$titel,$auteur,$datum);
$stmt->close();
}

【问题讨论】:

标签: php mysqli


【解决方案1】:
$mysqli = new mysqli('localhost', 'root', '', 'forum');
$query = "SELECT id,titel,auteur,datum FROM topics WHERE categorieid='$categorieid' ORDER by id DESC";

if ($mysqli->connect_errno) {
    printf("Connect failed: %s\n", $mysqli->connect_error);
    exit();
}

if ($result = $mysqli->query($query)) {
    printf("Select returned %d rows.\n", $result->num_rows);
    $result->close();
} else {
    printf("Select returned no rows.\n");
}

【讨论】:

    【解决方案2】:

    你需要尝试一下

    $mysqli = new mysqli('localhost', 'root', '', 'forum');
    $query = "SELECT id,titel,auteur,datum FROM topics WHERE categorieid='$categorieid' ORDER by id DESC";
    

    查询变量应该被引用。

    更多信息:- http://www.php.net/manual/en/mysqli-stmt.execute.php

    【讨论】:

    • 编辑了我的帖子并放置了那部分
    猜你喜欢
    • 2011-04-10
    • 1970-01-01
    • 2012-08-21
    • 2023-03-31
    • 1970-01-01
    • 2011-10-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多