Php 如何检查mysqli中的错误?
我有下面的代码。。。有时候,这段代码只是告诉我一切正常,以及“成功”消息。但insert中的新行并没有添加到数据库中。 我想:echo$this->mysqli->error;将给我错误,但它不工作Php 如何检查mysqli中的错误?,php,mysqli,Php,Mysqli,我有下面的代码。。。有时候,这段代码只是告诉我一切正常,以及“成功”消息。但insert中的新行并没有添加到数据库中。 我想:echo$this->mysqli->error;将给我错误,但它不工作 if ($stmt = $this->mysqli->prepare("INSERT INTO tournaments (" . "id_system, " . "id_rank_admin, "
if ($stmt = $this->mysqli->prepare("INSERT INTO tournaments ("
. "id_system, "
. "id_rank_admin, "
. "id_tournament_class, "
. "id_season, "
. "tournament_name,"
. "description,"
. "city,"
. "address,"
. "tournament_date,"
. "start_time,"
. "entry_fee,"
. "tournament_type,"
. "accepted_expansions,"
. "prices,"
. "additional_info,"
. "status,"
. "organizer_name,"
. "organizer_logo,"
. "organizer_link) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) "))
{
$stmt->bind_param("sssssssssssssssssss",
$this->id_system,
$this->id_rank_admin,
$this->it_tournament_class,
$this->id_season,
$this->tournament_name,
$this->description,
$this->city,
$this->address,
$this->tournament_date,
$this->start_time,
$this->entry_fee,
$this->tournament_type,
$this->accepted_expansions,
$this->prices,
$this->additional_info,
$this->status,
$this->organizer_name,
$this->organizer_logo,
$this->organizer_link);
$stmt->execute();
$stmt->close();
}
else
{
echo $this->mysqli->error;
}
我在这里找到了这个:
返回最近一次MySQLi函数调用的最后一条错误消息,该调用可能成功,也可能失败
可能会让您更好地了解错误所在。尝试以下方法:
$link = mysqli_connect("localhost", "my_user", "my_password", "db");
else
{
echo(mysqli_error($link));
}
mysqli->execute what is is returns true or false在此基础上你可以得到你的错误我不太了解mysqli oop的方式,所以如果任何语法错误,请更正它如果我没有错,使用mysqli只是不同风格的“程序化”而不是“面向对象”。。。
$link = mysqli_connect("localhost", "my_user", "my_password", "db");
else
{
echo(mysqli_error($link));
}
$ok=$stmt->execute();
if($ok)
{
echo "Query Executed Successfully";
}
else
{
echo(mysqli_error($link));
}