I have a doubt when using bindValue, I do not link the value of the variable to the sign placed in the query. I leave the code; I hope you can help me
<?php
$pdo = new \PDO('sqlite::memory:', null, null);
$pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
$error = false;
$crearTabla = "CREATE TABLE IF NOT EXISTS usuarios ('usuario' STRING NULL, 'password' STRING NULL,'email' STRING NULL)";
try{
$pdo->prepare($crearTabla)->execute();
echo "Tabla Creada\n";
} catch (PDOException $e) {
echo $e->getMessage();
}
$insertarUsuario = "INSERT INTO usuarios (usuario,password,email) VALUES ('Matias','yopassword','[email protected]')";
try{
$pdo->prepare($insertarUsuario)->execute();
echo "Usuario Insertado \n";
}catch(PDOException $e){
echo "Error al insertar el usuario \n".$e->getMessage();
$error = true;
}
if (!$error) {
$columna = 'usuario';
$consulta = 'SELECT ? FROM usuarios';
$stm = $pdo->prepare($consulta);
$stm->bindValue(1,'usuario', PDO::PARAM_STR);
$stm->execute();
$data = $stm->fetchAll(PDO::FETCH_OBJ);
echo "Datos".json_encode($data[0]);
}