Can you give me a hand with this error? I'm new to this ..
Fatal error: Uncaught ArgumentCountError: Too few arguments to function Base :: bind (), 2 passed in C: \ xampp \ htdocs \ guiacordoba \ app \ models \ User.php online 21 and exactly 3 expected in C: \ xampp \ htdocs \ guiacordoba \ app \ libraries \ Base.php: 39 Stack trace: # 0 C: \ xampp \ htdocs \ guiacordoba \ app \ models \ User.php (21): Base-> bind (': name', 'jhghj') # 1 C: \ xampp \ htdocs \ guiacordoba \ app \ drivers \ Pages.php (27): User-> addUser (Array) # 2 C: \ xampp \ htdocs \ guiacordoba \ app \ libraries \ Core.php (51): Pages-> add () # 3 C: \ xampp \ htdocs \ guiacordoba \ public \ index.php (6): Core-> __ construct () # 4 {main} thrown in C: \ xampp \ htdocs \ guiacordoba \ app \ libraries \ Base.php on line 39
Base.php
<?php
//Clase para conectarse a la base de datos y ejecutar consultas PDO
class Base{
private $host = DB_HOST;
private $usuario = DB_USUARIO;
private $password = DB_PASSWORD;
private $db_nombre = DB_NOMBRE;
private $dbh;
private $stmt;
private $error;
public function __construct(){
//configurar conexion
$dsn = 'mysql:host=' . $this->host . ';dbname=' .$this->db_nombre;
$opciones = array(
PDO::ATTR_PERSISTENT => true,
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
);
//Crear una instancia de PDO
try {
$this->dbh = new PDO($dsn, $this->usuario, $this->password, $opciones);
$this->dbh->exec('set names utf8');
} catch (PDOException $e) {
$this->error = $e->getMessage();
echo $this->error;
}
}
//Preparamos la consulta
public function query($sql){
$this->stmt = $this->dbh->prepare($sql);
}
//Vinculamos la consulta con bind
public function bind($parametro, $valor, $tipo){
if (is_null($tipo)) {
switch (true) {
case is_int($valor):
$tipo = PDO::PARAM_INT;
break;
case is_bool($valor):
$tipo = PDO::PARAM_BOOL;
break;
case is_null($valor):
$tipo = PDO::PARAM_NULL;
break;
default:
$tipo = PDO::PARAM_STR;
break;
}
}
$this->stmt->bindValue($parametro, $valor, $tipo);
}
//Ejecuta la consulta
public function execute(){
return $this->stmt->execute();
}
//Obtener los registros de la consulta
public function registros(){
$this->execute();
return $this->stmt->fetchAll(PDO::FETCH_OBJ);
}
//Obtener un unico registro
public function registro(){
$this->execute();
return $this->stmt->fetch(PDO::FETCH_OBJ);
}
//Obtener cantidad de filas con el metodo rowCount
public function rowCount(){
return $this->stmt->rowCount();
}
}
User.php
<?php
class Usuario{
private $db;
public function __construct(){
$this->db = new Base;
}
public function obtenerUsuarios(){
$this->db->query('SELECT * FROM clientes');
$resultados = $this->db->registros();
return $resultados;
}
public function agregarUsuario($datos){
$this->db->query('INSERT INTO clientes (nombre, email, telefono) VALUES (:nombre, :email, :telefono)');
$this->db->bind(':nombre', $datos['nombre']);
$this->db->bind(':email', $datos['email']);
$this->db->bind(':telefono', $datos['telefono']);
if ($this->db->execute()) {
return true;
}else{
return false;
}
}
}
I hope you can help me, thank you very much!