Answer the question
In order to leave comments, you need to log in
What's wrong with fetching data from the database?
All code
$host = 'localhost';
$database = 'data';
$user = 'root';
$pass = '';
$dsn = "mysql:host=$host;dbname=$database;";
$options = array(
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC
);
$pdo = new PDO($dsn, $user, $pass, $options);
$sql = $pdo->prepare("SELECT login FROM dataname WHERE id");
$sql->execute([$id]);
$data = $sql->fetch();
echo $data['login'];
$sql = $pdo->prepare("SELECT login FROM dataname WHERE id = ?");
Answer the question
In order to leave comments, you need to log in
$sql = $pdo->prepare('SELECT login FROM users WHERE id=?');
if ( $sql->execute(array($_GET['name'])) )
{
while ($row = $sql->fetchAll())
{
print_r($row);
}
}
$sql = $pdo->prepare('SELECT login FROM users WHERE id=?');
$sql->bindValue(1, $_GET['name']);
$sql->execute();
$data = $sql->fetch();
$sql = $pdo->prepare('SELECT login FROM users WHERE id=:id');
$sql-> execute(array(':id' => (int)$_GET['name']));
$data = $sql->fetchAll();
The documentation says that you need to pass an array to the execute method, try this:
$sql->execute(array([$id]));
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question