Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何获取mysqli OOP中受影响的_行数?Mysqli OOP受影响的_行返回-1_Php_Mysqli_Rows Affected - Fatal编程技术网

Php 如何获取mysqli OOP中受影响的_行数?Mysqli OOP受影响的_行返回-1

Php 如何获取mysqli OOP中受影响的_行数?Mysqli OOP受影响的_行返回-1,php,mysqli,rows-affected,Php,Mysqli,Rows Affected,获取mysqli OOP中受影响行数的exect方法是什么。我正在使用MSQLIOOP创建crud类。我得到int-1 $query = "SELECT * FROM `sk_courses`"; $stmt = $this->_mysqli->prepare($query); $stmt->execute(); $stmt->affected_rows ; var_dump($stmt->affected_rows);

获取mysqli OOP中受影响行数的exect方法是什么。我正在使用MSQLIOOP创建crud类。我得到int-1

    $query = "SELECT * FROM `sk_courses`";
    $stmt = $this->_mysqli->prepare($query);
    $stmt->execute();
    $stmt->affected_rows ;

    var_dump($stmt->affected_rows);    // output is int -1
var_dump($stmt)的输出为:


这是理解
mysqli_stmt
文档的一个问题,其中包括以下每个函数的页面

SELECT
查询不会影响任何行

查看手册中的[]。在返回值下:

-1 indicates that the query returned an error.
然而,这确实是一个复杂的问题

要获取行数,请尝试:

$query = "SELECT * FROM `sk_courses`";       // or
$query = "SELECT lastName, firstName, ... FROM `sk_courses`";

$stmt = $mysqli->prepare($query);
$stmt->execute();
$stmt->store_result();                      // without this line, num_rows = 0
print $stmt->num_rows;
然后,如果对结果集感兴趣,请添加:

// bind result variables. next statement 'binds' them in the order of the select query
$stmt->bind_result($last, $first, .... );  // must have variable for EACH column

while ($stmt->fetch()) {
    printf ("%s (%s)\n", $first, $last);
}

这很简单。只需阅读您正在使用的函数的手册页。对这样的问题进行投票是一种耻辱。为编程的艺术感到羞耻。重复@YourCommonSense。。在评论之前,你是否试图正确理解我的问题。。?$stmt->infected_行的输出为-1是的,我完全理解您的两个问题。要么你不知道它的用途,要么就是你真正的问题
// bind result variables. next statement 'binds' them in the order of the select query
$stmt->bind_result($last, $first, .... );  // must have variable for EACH column

while ($stmt->fetch()) {
    printf ("%s (%s)\n", $first, $last);
}