我在下面有一个代码…有时这段代码只是给我一切正常的信息,和"success" msg。但是,插入的新行不会添加到数据库中。我想:echo $this->mysqli->error;会给我错误,但它不工作?
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;
}
$ok=$stmt->execute();
if($ok)
{
echo "Query Executed Successfully";
}
else
{
echo(mysqli_error($link));
}
mysqli->执行它所做的是根据它返回true或false你可以得到你的错误我不太喜欢mysqli oop方式所以如果任何语法错误,请纠正
我在这里找到了这个:http://php.net/manual/en/mysqli.error.php
string mysqli_error ( mysqli $link )
返回最近一次MySQLi函数调用的最后一个错误消息,可以成功也可以失败。
可以让您更好地理解错误在哪里
试试这个:
$link = mysqli_connect("localhost", "my_user", "my_password", "db");
else
{
echo(mysqli_error($link));
}