Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/70.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_结果_Php_Mysql_Mysqli - Fatal编程技术网

PHP扩展mysqli_结果

PHP扩展mysqli_结果,php,mysql,mysqli,Php,Mysql,Mysqli,我在扩展mysqli\u结果类时遇到问题 我试图用一个自定义类扩展mysqli\u结果类。 这是我的密码: class mysqli_result_extended extends mysqli_result { public function GetJSON() { blah blah... return $json; } } $db = new mysqli('localhost','root','*****','somedb'); $sql

我在扩展
mysqli\u结果
类时遇到问题

我试图用一个自定义类扩展
mysqli\u结果
类。 这是我的密码:

class mysqli_result_extended extends mysqli_result {

  public function GetJSON() {
    blah blah...
    return $json;   
  }       
}

$db = new mysqli('localhost','root','*****','somedb');

$sql = 'SELECT * FROM students';

$result = $db->query($sql);

$result->getJSON(); //This is causing the trouble
当我运行上述代码时,它给出了一个错误:

Call to undefined method mysqli_result::getJSON() in ****.php on line **

此代码有什么问题?

之所以出现错误,是因为
$db->query($sql)
返回的变量类型为
mysqli\u result
,而不是
mysqli\u result\u extended
mysqli\u结果
类没有名为
getJSON
的方法

因此,当您定义一个扩展类
a
的类
B
时,并不意味着基类
a
的所有实例都会神奇地变成类
B