'Fatal error: Call to a member function prepare() on null problem here
Fatal error: Call to a member function prepare() on null
public function __construct(){
require_once('DbConnect.php');
$db = new DbConnect();
$this->dbConn=$db->connect();
}
public function insert(){
$sql="INSERT INTO $this->tableName VALUES(null,:name,:type,:pages,:price,:author,:cdate)";
$stmt=$this->dbConn->prepare($sql);
$stmt->bindParam(':name',$this->name);
$stmt->bindParam(':type',$this->type);
$stmt->bindParam(':pages',$this->pages);
$stmt->bindParam(':price',$this->price);
$stmt->bindParam(':author',$this->author);
$stmt->bindParam(':cdate',$this->createdDate);
if($stmt->execute()){
return true;
}else{
return false;
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|