简体   繁体   English

PDO::FETCH_OBJ php

[英]PDO::FETCH_OBJ php

PDO::FETCH_OBJ -> Returns an anonymous object with property names that correspond to the column names returned in your result set. PDO::FETCH_OBJ -> 返回一个匿名对象,其属性名称与结果集中返回的列名称相对应。 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!请帮我解决这个问题 24 小时......我知道它很简单,因为我以前做过......似乎不记得找到任何引用代码!

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.您可以在粘贴的内容中看到 $results 是一个对象数组,因此您需要指定数组中的哪个项目才能获得正确的电子邮件结果。

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:您可以将 count() 与 $results 变量一起使用,如下所示:

if (count($results)==1) {
      print_r($results[0]->email);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM