-1
我已經在下面的類中使用了連接。「在非對象上調用成員函數returnQuery()」PHP
class createConnection //create a class for make connection
{
var $host="localhost";
var $username="root"; // specify the sever details for mysql
var $password="";
var $database="quiz";
var $myconn;
function _construct()
{
$conn = mysqli_connect($this->host,$this->username,$this->password,$this->database);
if(!$conn)// testing the connection
{
die ("Cannot connect to the database");
}
else
{
$this->myconn = $conn;
}
return $this->myconn;
}
function returnQuery($query) // call procedure
{
if ($result = mysqli_query($this->myconn ,$query) or die(mysqli_error($this->myconn))) {
return $result;
}
else {
return '0';
}
}
}
現在,我想從另一個類調用returnQuery()函數像如下─內容時發生像下面
require('connect.inc.php');
class QCategory{
private $link;
public function _constuct()
{
$this->link = new createConnection();
}
public function GetParentCategoryList() {
$query = "CALL GetParentQCategoryList()";
if ($result = $this->link->returnQuery($query)) {
return $result;
}
else {
return '0';
}
}
}
但錯誤 - 致命錯誤:調用一個成員函數returnQuery()上第5行的C:\ wamp \ www \ quiz \ include \ qcategory.php中的非對象
儘快幫助我!
'_constuct'不會被調用,因爲它不是爲構造適當的標識符。 – mario
請不要添加「儘快幫助我!」等短語。對你的問題。如果問題本身很明確,人們更有可能提供更快更好的答案。有關更多信息,請參閱[如何提問](http://stackoverflow.com/help/how-to-ask)。 – Sumurai8