0
我想實現準備好的語句,但由於某種原因,我無法創建用戶。請注意,我已經能夠在舊的傳統定義[mysql_connect和...]中創建具有相同值的用戶了嗎?某些機構可以幫助我確定我犯的錯誤嗎?php/mysql使用準備好的語句回顧
require_once 'config.php';
class AuthDb {
private $db;
function __construct(){
$this->db = mysqli(DB_SERVER, DB_USER, DB_PASS, DB_NAME)
or die('could not connect');
}
function __destruct(){
$this->db->close();
unset($this->db);
}
public function createUser($name, $email) {
$query = "INSERT INTO myUsers (name, email) VALUES (?, ?)";
$stmt = $this->db->prepare($query);
$stmt->bind_param("ss", $name, $email);
if ($stmt->execute()){
return true;
}
return false;
}
}
$create = new AuthDb();
$name = "bing";
$email = "[email protected]";
$test = $create->createUser($name, $email);
'$這個 - > DB = mysqli的(DB_SERVER' - ?你忘在這裏了'new' – VolkerK 2012-02-20 15:49:28
mysqli的是一個功能,我爲什麼需要它實例 – 2012-02-20 16:10:44
我只是好奇,因爲有一個?類名爲'mysqli'和'config.php'聽起來不像它會提供一個稱爲mysqli(...);-)的函數 – VolkerK 2012-02-20 16:16:09