Hello
I'm running a php function to get some user information from mysql using pdo. The problem is that i don't get the results i want. This is my php code:
<?php
require_once('db_connect.php');
function mila(){
global $dbh;
// Set dummy variables
$required_id=1;
// Select table with query
$sth = $dbh->prepare("SELECT username,firstname FROM users WHERE :id");
// Bind variables to your statement
$sth->bindParam(':id', $required_id);
// Flip the switch
$sth->execute();
foreach ($sth as $row){
$username = $row['username'];
$firstname = $row['firstname'];
echo '<br/>' .$username.' '.$firstname;
}
}
mila();
?>
Below is the database table i access:
And i get this on my browser:
user1 name1
user2 name2
user3 name3
user4 name4
I should get only one record, because of my sql query.
If i use "SELECT username,firstname FROM users WHERE id=1" as my query, i get only on record.