我有这个我无法弄清楚的问题,我以这种方式查询数据库:
$stmt = $this->pdo->prepare('SELECT customer_name FROM active_users WHERE a_id= ?');
$stmt->execute(array($a_id));
$c_name = $stmt->fetch(PDO::FETCH_OBJ);
API::writeToLog('CMD=leave , Customer_Name = ' . $c_name->customer_name, $customer_name);
这: $c_name->customer_name 给出以下错误:
Notice: Trying to get property of non-object
如何迭代我的数据库, fetch 和 fetchAll 有什么区别?我应该使用哪个?
这是数据库架构:
+---------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------------+--------------+------+-----+---------+-------+
| a_id | varchar(40) | NO | PRI | NULL | |
| token | varchar(64) | NO | | NULL | |
| nick | varchar(255) | NO | | NULL | |
| ip | varchar(32) | NO | | NULL | |
| customer_name | varchar(255) | YES | | NULL | |
+---------------+--------------+------+-----+---------+-------+
谢谢!
编辑:修正了一个错字..