PHP $ MySqli-> fetch始终从MySQL表返回0个结果

时间:2018-09-14 12:53:51

标签: php mysqli

即使直接sql测试返回1个结果,此代码也始终返回0。我在整个代码中进行了错误检查,以查看每个步骤是否返回true或结果。我想,我忘记了一些明显的东西,但是我非常沮丧,看不到它。

// Create connection
$mysqli = new mysqli($servername, $username, $password, $database);

// Check connection
if ($mysqli->connect_error) { die("Connection failed: " . $mysqli->connect_error);}

//--------------------------Connection Successful -----------------------------//
$t1 = "SELECT * FROM `customer_info` WHERE `transaction` = ?";
$transaction = "345673245Vkd_";

if ($mysqli->connect_error) {
    printf('connect error (%d) %s', $mysqli->connect_errno, htmlspecialchars($mysqli->connect_error)); }


$stmt = mysqli_prepare($mysqli, $t1);

if ( !$stmt ) { printf('prepare failed: %s', htmlspecialchars($mysqli->error)); }

$rc = mysqli_stmt_bind_param($stmt,'s',$transaction);
if ( !$rc ) { printf('bind_param failed: %s', htmlspecialchars($stmt- >error)); }

$rc = mysqli_execute($stmt);
if ( !$rc ) { printf('execute failed: %s', htmlspecialchars($stmt->error)); }

 mysqli_stmt_bind_result($stmt, $match['0'],$match['1'], $match['2'],$match['3'], $match['4'], $match['5'], $match['6'], $match['7'], $match['8'], $match['9'], $match['10'], $match['11'], $match['12'], $match['13']);

 print_r($match); echo "<br>";

 while($test = $stmt->fetch()){
      printf("%s %s\n", $match['0'], $match['1'], $match['2'], $match['3'],$match['4'], $match['5'], $match['6'], $match['7'], $match['8'], $match['9'], $match['10'], $match['11'], $match['12'], $match['13']);
    echo $stmt->num_rows();

}

$stmt->num_rows();
echo mysqli_stmt_num_rows($stmt);

此打印

 Array ( [0] => [1] => [2] => [3] => [4] => [5] => [6] => [7] => [8] => [9] => [10] => [11] => [12] => [13] => ) 
 Array ( [0] => [1] => [2] => [3] => [4] => [5] => [6] => [7] => [8] => [9] => [10] => [11] => [12] => [13] => )

并且通过所有错误检查没有错误。

// ----------------------更新---------------------- -// 删除WHERE transaction =吗? 返回:

Array ( [0] => 
[1] => 345673245Vkd_ 
[2] => rem_reb_dpljnzl 
[3] => blank.email@hotmail.com 
[4] => eBook Title Example 
[5] => 302864487819 
[6] => $1.99 [7] => 1 
[8] => Remmy 
[9] => Example 
[10] => 1122 Example Drive 
[11] => United States 
[12] => MO [13] => 12345 )

0 个答案:

没有答案