We have this class for database. Calling the query
function works fine if the query string is SELECT..
but it doesn't wotk for UPDATE...
queries.
The issue is $stmt->fetchAll();
, it can't fetchAll
on UPDATE...
and it make sense.
How can I tell if the query can fetchAll
able or not.
class DB
{
public $db = null;
public function __construct() {
try {
$this->db = new PDO('mysql:host=' . DBHOST . ';dbname=' . DBNAME, DBUSER, DBPWORD);
$this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$this->db->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, 1);
} catch(PDOException $e) {
}
}
public function query( $query = "" , $params = [] ) {
$stmt = $this->db->prepare( $query );
foreach( $params as $param ) {
$stmt->bindParam($param[0], $param[1]);
}
$stmt->execute();
$records = $stmt->fetchAll(); //How can I tell if I can do this.
return $records;
return true;
}
}
Thanks for the help.