gpt4 book ai didi

php - 命名空间内的 Mysqli

转载 作者:行者123 更新时间:2023-12-04 17:03:02 26 4
gpt4 key购买 nike

我需要在命名空间中使用 mysqli 和准备好的语句,这一直工作正常,直到我尝试绑定(bind)参数,它连接 find 和 prepare 工作,但在那里形成我收到一个错误,说调用未定义的方法。

我已经用谷歌搜索了这个,我能从谷歌找到的就是做

use Mysql;

但这似乎没有帮助。堆栈溢出是我最后的手段。

这是整个页面:
<?php

namespace KrowdUp\Core;

use Mysql;

class DatabaseConnect
{

private $user;
private $password;
private $database;
private $server;

//Variable for database connect
public $db;
//Variable for sql
public $dbSQL;
//Variable for db transaction
public $getData;
//Variable for db error
public $dbERROR;



public function __construct()
{

$this->user = "user";
$this->password = "password";
$this->database = "databse";
$this->server = "server";

$this->db = new \mysqli($this->server, $this->user, $this->password, $this->database);

if($this->db->connect_errno > 0){
die('Unable to connect to database [' . $db->connect_error . ']');
//Handle error
}

}

//Set the SQL
public function setSQL($sql)
{

$this->dbSQL = $sql;

}



//Check the SQL
public function checkSQL()
{

if ($this->getData = $this->db->prepare($this->dbSQL)) {

$this->dbERROR = 1;
return 1;
//Handle error properly

} else {

$this->dbERROR = 0;
return 0;
//Handle error properly

}

}

//Bind paramaters
public function bindParam($param)
{

$this->db->bind_param('i',$param);

}

}

这是因为我在做一些愚蠢的事情而没有注意到还是我错过了什么?预先感谢您的帮助。

最佳答案

bind_param 是 mysqli_statement 的函数,而不是 mysqli 连接

尝试

$this->getData->bind_param('i', $param);

http://php.net/manual/en/mysqli-stmt.bind-param.php

关于php - 命名空间内的 Mysqli,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30417943/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com