[英]How to access column-values before fetching?
I need the values of one columns before fetching the query. 在获取查询之前,我需要一列的值。 Something like this: 像这样:
// mytable
+----+-------+
| id | codes |
+----+-------+
| 1 | 102 |
| 2 | 64 |
| 3 | 563 |
| 4 | 79 |
+----+-------+
My query: 我的查询:
$db = new PDO("mysql:host=localhost;dbname=mydb", "root", "");
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sth = $db->prepare("SELECT * FROM mytable");
$sth->execute();
/* I need to those numbers in the codes-column as an array in here */
while ($results = $sth->fetch()) {
var_dump($results);
}
Well, how can I access this array [0]=>102, [1]=>64, [2]=>563, [3]=>79
before that while()
in the above code? 那么,如何在上述代码中的while()
之前访问此数组[0]=>102, [1]=>64, [2]=>563, [3]=>79
?
Note: Preferably without the use of fetchAll();
注意:最好不使用fetchAll();
Your question is like saying How can I fetch data without fetching it ? 您的问题就像是说如何在不获取数据的情况下获取数据?
This is obviously impossible, you will need to fetch it at some point in your application. 这显然是不可能的,您将需要在应用程序中的某个时刻获取它。
if($results = $sth->fetch()) {
var_dump($results);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.