当我尝试使用PHP更新我的数据库时,我是PHP OOP编程的新手,它抛出了我的异常,查询也运行完美,数据库也更新。但它仍然把这个错误抛给了我
/var/www/html/thaalinda/includes/querys.inc.php:8异常堆栈跟踪:#0 /var/www/html/thaalinda/includes/test.php(12):adminQuery-> insertquery(Object(mysqli),' INSERT INTO ff(...')#1 {main}
这是我的数据库连接代码:
<?php
class admindatabase{
protected $host = "localhost";
protected $database = "testmy";
protected $user = "lkd";
protected $pwd = "";
public $connection;
public function connect(){
$connection = new mysqli($this->host , $this->user , $this->pwd , $this->database);
if(mysqli_connect_errno()){
printf("Connect error:%S\n",mysqli_connect_errno());
exit();
}
else{
return $connection;
}
}
public function disconnect(ab $connection){
$connection->close();
}
}
?>
这是我的查询类
<?Php
class adminQuery{
public function insertquery($con , $query){
try {
$con->query($query);
throw new Exception($con->error);
} catch (Exception $e) {
echo $e;
}
}
}
?>
这是我的测试PHP
<?Php
require "./admindatabase.inc.php";
require "./querys.inc.php";
$myob = new admindatabase();
$connection = $myob->connect();
$query = new adminQuery();
$query->insertquery($connection,'INSERT INTO ff(ok) VALUES("Thaalinda BAndara")');
?>
答案 0 :(得分:0)
587
在$ con&gt;错误时将其置于某种状态。