PDO::FETCH_OBJ -> Returns an anonymous object with property names that correspond to the column names returned in your result set. For example:
Array ( [0] => stdClass Object ( [id] => 3 [email] => frank@frank.com [password] => password [salt] => salt [devices] => 1 [accounttype] => 1 [accountcreated] => 2014-03-26 [confirmed] => 1 [confirmcode] => 0 [logindate] => 2014-03-26 ) )
How do I get the email value??????? Below is what i have so far
$_db = DB::getInstance();
$_db = $_db->query('SELECT * FROM users WHERE email = ? AND password = ? ', array($email, $pass));
$results = $_db->results();
print_r($results);
print_r($results->email); <<<<<<<<<<<--- does not work!
PLEASE HELP been at this for 24hours.... I know its simple because I have done it before... just cant seem to remember of find any referencing code!
You can see in what you pasted that $results is an array of objects, so you need to specify which item in the array to get a proper result for email.
Example:
print_r($results[0]->email);
You should use something like the following:
foreach ($results as $row) {
print_r($row->email);
}
If you expect to have just one row returned, it is always a good idea to check that. You can use count() with your $results variable like this:
if (count($results)==1) {
print_r($results[0]->email);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.