Jump to content

Using PDO to query a database?


Mr Chris

Recommended Posts

Hello All,

 

Trying to write a log-in script using PDO.  But have one question.  With the below when I query the database and even run a print_r on $RES nothing is outputted?

 

Any ideas?

 

Thanks

 


if (isset($_POST['Submit']))
{
$email  = $_POST['email'];
$password  = $_POST['password'];

$QUERY = $dbc->prepare("SELECT email, password FROM tbl WHERE email = :email");
$QUERY->bindParam(':email', $email);
$QUERY->execute();
$RES = $QUERY->fetchColumn();

echo "Email is:".$RES['email'];
echo "PW is: ".$RES['password'];
print_r($RES);
}

 

Link to comment
https://forums.phpfreaks.com/topic/216394-using-pdo-to-query-a-database/
Share on other sites

fetchColumn() as you are using it only returns the value of the first column in the first row.  You probably want fetch() to fetch the entire row.  Also, if there is nothing there, then there were no results returned.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.