即使mysql表中有值,SQL查询也不返回值
I got this function:
private function _loadColumnRights() {
$db = Zend_Registry::get('db');
// Create the select query
$select = $db->select()
->from('account_columns', array(
'accountId'
))
->where('accountId = ?', $this->getId());
// Fetch the data
$row = $db->fetchRow($select);
if($row != null) {
$this->setColumns($row['columns']);
}
else {
$this->setColumns('');
}
}
I search for the accountID = '128'
My table looks like this:
accountId | columns
and at row with accountId = '128'
I got a value like this 'orderdate,ref-corlido,item-no,partid,item-description,quantity-value,unit-of-measurement,acquisition-value-order-line,sales-value-order-line,markup,due-date,status,direct-delivery,out-of-scope,non-compliant,memo,request-document,documents'
If I in PHP manually execute this SQL statement:
SELECT * FROM `account_columns` WHERE `accountId` = '128'
Then I get result..
my Code also goes in to this if:
if($row != null) {
$this->setColumns($row['columns']);
}
But the value of $row['columns'
] is empty.. If I perform a var_dump on my view on this getter then i get empty values
If I change $row['columns']
) to :
$this->setColumns($row['accountId']);
then I get the 128 value.. But I don't get the column values.. How come?
我有这个函数: p>
private function _loadColumnRights() {
$ db = Zend_Registry :: get('db');
//创建选择查询
$ select = $ db-> select()
- > from('account_columns ',array(
'accountId'
))
- > where('accountId =?',$ this-> getId());
//获取数据
$ row = $ db-> fetchRow($ select);
if($ row!= null){
$ this-> setColumns($ row ['columns ']);
}
其他{
$ this-> setColumns('');
}
}
code> pre>
我搜索 accountID ='128' code> p>
我的表格如下所示: p>
accountId | 列 p>
和 accountId ='128' code>的行我得到了一个像'orderdate,ref-corlido,item-no,partid,item-description的值 ,数量值,单元的测量,采集值阶线,销售值阶线,标记,到期日,状态,直接递送,外的范围,不符合规定的,备忘录 ,请求文档,文档' p>
如果我在PHP中手动执行此SQL语句: p>
SELECT * FROM`count_columns` WHERE` accountId` ='128'
code> pre>
然后我得到结果.. p>
如果符合以下情况,我的代码也会进入:
if($ row!= null){
$ this-> setColumns($ row ['columns']);
}
code>
但 $ row ['columns' code>]的值为空..如果我在此getter上的视图上执行var_dump,那么我得到空值 p>
如果我将 $ row ['columns'] code>更改为: p>
$ this-> setColumns( $ row ['accountId']);
code> pre>
然后我得到128值..
但是我没有得到列值 ..怎么来的? p>
div>
Because you only ask for one column in the result row. :)
You only as k for accountId
...
private function _loadColumnRights() {
$db = Zend_Registry::get('db');
// Create the select query
$select = $db->select()
// THERE IS YOU ERROR :)
// THE SECOND PARAMETER IS AN ARRAY OF RESULT COLUMNS
->from('account_columns', array(
//'accountId', <-- Your error :)
'*' // use this if you want all columns back
//'columns' // or add this column name
))
->where('accountId = ?', $this->getId());
// Fetch the data
$row = $db->fetchRow($select);
if($row != null) {
$this->setColumns($row['columns']);
}
else {
$this->setColumns('');
}
}
P.S.: You really should use another name for the "columns" colmn... :) Look at the list of reserved words and keywords... don't use them for column or table names. :)
https://dev.mysql.com/doc/refman/5.7/en/keywords.html
Have a great day!
Good luck!