this error happened while i was trying to create an insert query
Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error in E:\xammp\htdocs\school\private\core\database.php:29 Stack trace: #0 E:\xammp\htdocs\school\private\core\database.php(29): PDOStatement->fetchAll(5) #1 E:\xammp\htdocs\school\private\core\model.php(40): Database->query('insert into use...', Array) #2 E:\xammp\htdocs\school\private\controllers\Home.php(18): Model->insert(Array) #3 E:\xammp\htdocs\school\private\core\app.php(33): Home->index() #4 E:\xammp\htdocs\school\public\index.php(6): App->__construct() #5 {main} thrown in E:\xammp\htdocs\school\private\core\database.php on line 29
this is the query
public function query($query, $data = array(),$data_type = "object"){
$con = $this -> connect();
$stm = $con->prepare($query);
if($stm){
$check = $stm -> execute($data);//check if the statment excuted or it went well
if($check){
if ($data_type == "object") {
$data = $stm->fetchAll(PDO::FETCH_OBJ);
}else{
$data = $stm->fetchAll(PDO::FETCH_ASSOC);
}
if(is_array($data) && count($data)){
print_r($data);
}
}
}
return false;
}
this is the insert method
public function insert($data)
{
$keys = array_keys($data);
$columns = implode(',', $keys);
$values = implode(',:', $keys);
$query = "insert into $this->table ($columns) values (:$values)";
return $this -> query($query,$data);
//insert to the table
}
An INSERT query does not generate anything fetchable. As you have observed, PDO gacks (gacks === throws an obscure exception) when you try to use .fetchAll()
from a statement containing INSERT.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.