0

My problem is, when i want to read datas from database with zend framework 1, I get the exactly same result even if i use different conditions.
My table named 'maps' contains 2 rows:

id: 1 date: date1 description: sth1 userid: 30  
id: 2 date: date2 description: sth2 userid: 30

application.ini:

resources.db.params.charset = "utf8"  
resources.db.adapter = pdo_mysql  
resources.db.params.host = localhost  
resources.db.params.username = root  
resources.db.params.password =  
resources.db.params.dbname = gallery  

in my controller:

$gallery = new Gallery_Model_DbTable_Maps();  
$maps = $gallery->getMaps($user_id);  
$this->view->datas = array(
     'maps' => $maps,
);

in my model:

class Gallery_Model_DbTable_Maps extends Zend_Db_Table_Abstract  
{  
    protected $_name = 'maps';  
    public function getMaps($id){  
        $select = $this->select();  
        $select->where('userid = ?', $id);  
        $rows = $this->fetchAll();  
        return $rows->toArray();  
    }  
}

If I replace the "$id" to something else than 30 in "Gallery_Model_DbTable_Maps" I always get the 2 rows mentioned above... If I change the function for this...

 public function getMaps($id){  
    $dbAdapter = Zend_Db_Table::getDefaultAdapter();
    $stmt = $dbAdapter->query('SELECT * FROM maps WHERE userid = 32');
    $rows = $this->fetchAll()->toArray();
    return $rows;
 }

...the problem still occurs, and get the same result. But if i run the query in the phpmyadmin, everything is fine

And one additional think(maybe help to find out what is the problem), if i use joins, the joined table datas doesn't appear in the result(in zf structure), but if i run this query(containing join) in phpmyadmin, everything is fine.

1 Answer 1

1

try this:

$select = $this->select();  
$select->where('userid = ?', $id);  
$rows = $this->fetchAll($select); // rowset

Read more about it here

If you work with Zend_Db_Adapter it goes like:

$dbAdapter = Zend_Db_Table::getDefaultAdapter();
$sql = 'SELECT * FROM maps WHERE userid = ?';
$rows = $dbAdapter->fetchAll($sql, $id); // array

Read more about it here

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks, it was the problem.
$dbAdapter = Zend_Db_Table::getDefaultAdapter(); $stmt = $dbAdapter->query('SELECT * FROM maps WHERE userid = 32'); $rows = $this->fetchAll()->toArray(); return $rows;
Could you help me in the query based result(in my last syript in here)?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.