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范围......我不确定我应该传递什么。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值