我正在尝试使用准备好的查询,但此代码无法正常工作,它只是第一次使用prepare()。评论拳头if()什么都不做,现在它在第二。没有连接问题/没有错误,只是卡住了。准备好的查询不起作用PHP
如果我只使用mysqli_query()来完成所有工作,那么所有工作都很好。
function addUser($id){
/*
if ($stmt = $this->mysqli->prepare("SELECT * FROM Users WHERE ID = ?")){
if (!($stmt->bind_param("s", $id))){
return false;
}
if ($stmt->execute()) {
if ($stmt->num_rows!=0){
return false;
}
}else{
return false;
}
}else{
return false;
}*/
if ($stmt = $this->mysqli->prepare("INSERT INTO Users VALUES (?, '')")) {
if (!$stmt->bind_param("s", $id)) {
return false;
}
if (!$stmt->execute()) {
return false;
}
return true;
}
return false;
}
和有关调试,如果我改变这样
function addUser($id){
echo "1";
if ($stmt = $this->mysqli->prepare("SELECT * FROM Users WHERE ID = ?")){
echo "2";
if (!($stmt->bind_param("s", $id))){
return false;
} ...
}else{
echo "3";
} ...
的代码,我会看到只有“1”的页面上。类的
开始:
class db{
private $mysqli;
function __construct($ip, $login, $password, $database){
$this->mysqli = new mysqli($ip, $login, $password, $database) or die("Problem with DB connection!");
$this->mysqli->set_charset("utf8");
}
单'='你分配一个值,双您比较。哎呀,别介意,误解你的代码 – RST 2014-09-26 21:10:53
我建议你实际检查并注销你的错误。目前,您的代码在数据库交互中完全没有错误处理。 – 2014-09-26 21:11:00
@RST在这种情况下需要一个'='。 – 2014-09-26 21:13:26