-2
my project is not working because it gives the following errors:
Warning: include(Models PDO.php): Failed to open stream: No such file or directory in C: xampp htdocs Resumeai index.php on line 3
Warning: include(): Failed Opening 'Models PDO.php' for inclusion (include_path='C: xampp php PEAR') in C: xampp htdocs Resumeai index.php on line 3
Fatal error: Uncaught Error: Class "Models PDO" not found in C:
I saw that if you use PDO you can instantiate, but it does not work in the code. It is below.
<?php
namespace Models;
use \PDO;
class database{
private $connection;
public function __construct(){
$this->setConnection();
}
public function setConnection(){
try{
$this->connection = new PDO("mysql:dbname=resumeai;host=localhost;", "root", "");
$this->connection->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
return $this->connection;
}catch(PDOException $e){
die('erro ao conectar!');
}
}
public function getPDO(){
return $this->connection;
}
}
?>
<?php
namespace Models;
require_once 'database.php';
class HomeModel{
private $db;
private $pdo;
public function __construct(){
$this->db = new database();
$this->pdo = $this->db->getPDO();
}
public function login($email, $senha){
}
public function register($nome, $email, $senha){
$sql = $this->pdo->prepare("INSERT INTO usuario(nome, email, senha) VALUES( ?, ?, ?)");
$sql->bindValue(1, $nome, PDO::PARAM_STR);
$sql->bindValue(2, $email, PDO::PARAM_STR);
$sql->bindValue(3, $senha, PDO::PARAM_STR);
var_dump($sql);
$sql->execute();
// if($sql->execute()){
// return true;
// }else{
// return false;
// }
}
public function getC(){
return $this->pdo;
}
}
?>