I'm finding the following error in the script below:
Fatal error: Call to a member function prepare () on null in C: \ wamp \ www \ cursophp \ object_address \ pdo_statement \ users.php on line 20
Code:
class Usuarios {
private $db;
public function _construct(){
try{
$this->$db = new PDO("mysql:dbname=blog;host=localhost", "root", "");
}catch(PDOException $e){
echo " Falha na conexão: ".$e->getMessage();
}
}
public function selecionar($id) {
$sql = $this->db->prepare("SELECT * FROM usuarios WHERE id=:id");
$sql->bindValue(":id", $id);
$sql->execute();
$array = array();
if($sql->rowCount() > 0){
$array = $sql->fetch();
}
return $array;
}