php mysql函数未定义,PHP MySQLi未定义的方法错误
我使用MySQLi創建了一些基本的OO腳本,并且當我使用stmt_init(),prepare()或query()...時發生未定義的方法錯誤...并且connect_errno()出現錯誤。我知道在我的php.ini中啟用了mysqli擴展(未注釋),phpinfo()同時啟用了mysqli和mysqlnd ...所以不知道為什么我無法訪問方法/屬性。我得到的錯誤是:
致命錯誤:調用未定義的方法mysqli :: connect_error()
class db {
public $host = 'localhost';
public $username = 'root';
public $password = '';
public $database = 'molecule';
public $mysqli = '';
function __construct() {
$this->mysqli = new mysqli($this->host, $this->username, $this->password, $this->database);
return $this->mysqli;
}
}
class nodeModel {
function __construct() {
$this->mysqli = new db;
if($this->mysqli->connect_error()){ printf("Database Connection failed: %s\n", $this->mysqli->connect_error()); }
}
function insertNode() {
$this->insert = $this->mysqli->stmt_init();
$this->insert->prepare("INSERT INTO node(node_name, node_link, node_comment) VALUES (?, ?, ?)");
$this->insert->bind_param($this->node_name, $this->node_link, $this->node_comment);
if($this->insert->execute()) {
$this->insert_id = $this->mysqli->insert_id;
}
$this->insert->close();
print_r($this->insert_id);
return $this->insert_id;
}
因此,要使insertNode()方法正常工作......這些是我放入nodeModel類的其他方法
public function setNodeName($value) { $this->nodeName = $value; }
public function setNodeLink($value) { $this->nodeLink = $value; }
public function setNodeComment($value) { $this->nodeComment = $value; }
public function getNodeName() { return $this->nodeName; }
public function getNodeLink() { return $this->nodeLink; }
public function getNodeComment() { return $this->nodeComment; }
public $insert_id;
function insertNode($nodeName, $nodeLink, $nodeComment) {
$this->mysqli->stmt_init();
$this->mysqli->prepare("INSERT INTO node(node_name, node_link, node_comment) VALUES (?, ?, ?)");
$this->mysqli->bind_param($this->node_name, $this->node_link, $this->node_comment);
if($this->mysqli->execute()) {
$this->insert_id = $this->mysqli->insert_id;
}
$this->mysqli->close();
print_r($this->insert_id);
return $this->insert_id;
}我如何將變量傳遞給方法?我正在嘗試這個...
$connect = new db();
$db = new nodeModel($connect);
$db->setNodeName('My Node Title');
$db->setNodeLink('My Node Link');
$db->setNodeComment('My Node Comment. This one should be longer so I will write more stuff');
$db->insertNode($db->getNodeName(), $db->getNodeLink(), $db->getNodeComment());但這不起作用。我的困惑實際上是關于類方法內部的OO范圍......我不確定我應該傳遞什么。
總結
以上是生活随笔為你收集整理的php mysql函数未定义,PHP MySQLi未定义的方法错误的全部內容,希望文章能夠幫你解決所遇到的問題。
                            
                        - 上一篇: 好听的帮会名字大全
 - 下一篇: 《宿竹阁》第八句是什么