返回行数不起作用

时间:2014-10-19 00:32:18

标签: php mysql prepared-statement

这是我目前的代码:

    $stmt = $mysqli->prepare("SELECT * FROM Account WHERE accountKey=? AND accountUsername=?");
    $stmt->bind_param('ss', $key,$username);

    $stmt->execute();
    $stmt->store_result();
    $numrows = $stmt->num_rows;

问题是查询没问题。我在PHPMyAdmin上尝试了它,它返回了一个结果。当我检查我得到了多少结果时,这个结果总是0,它应该是1 ...你知道会发生什么......

来自PHPMyAdmin的查询: http://i.imgur.com/PFrXNgf.png

1 个答案:

答案 0 :(得分:0)

<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);

include("../script/connection.php"); 

$link = mysqli_connect($SQLhost, $SQLusername, $SQLpassword, $SQLdatabase);

if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}

$key = '4dc5f0ea67ca3791614b28c310cd1c79';
$username = 'jean8mathieu';

$query = "SELECT * FROM Account WHERE accountKey=? AND accountUsername=?";

if ($stmt = mysqli_prepare($link, $query)) {
    mysqli_stmt_bind_param($stmt, 'ss', $key, $username);
    mysqli_stmt_execute($stmt);
    mysqli_stmt_store_result($stmt);
    printf("Number of rows: %d.\n", mysqli_stmt_num_rows($stmt));
    mysqli_stmt_close($stmt);
} else {
   printf('errno: %d, error: %s', $mysqli->errno, $mysqli->error);
   exit;
}

mysqli_close($link);