我需要在命名空间内使用mysqli和prepared语句,这一点工作正常,直到我尝试绑定参数,它连接查找和准备工作,但在那里形成我得到一个错误说调用未定义的方法。
我已经使用谷歌搜索了所有我可以从谷歌找到的东西
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);
}
}
这是因为我做了一些愚蠢而没有注意到的事情,或者我错过了什么?提前感谢您的帮助。
答案 0 :(得分:1)
bind_param是mysqli_statement的函数,而不是mysqli连接
尝试
$this->getData->bind_param('i', $param);