日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

php mysql函数未定义,PHP MySQLi未定义的方法错误

發布時間:2023/11/27 生活经验 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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未定义的方法错误的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。