我需要你的帮助! 我正在创建一个应用程序,使用zend框架1管理每个页面的文章。我想为每个页面显示其文章。
public function getPagearticle(){
$db = Zend_Db_Table::getDefaultAdapter();
$select = new Zend_Db_Select($db);
$select = $db->select()
->from(array('a' => 'articles'), array('page_id', 'Nom_article'))
->join(array('p' => 'pages'), 'p.id = a.page_id',array('p.nom'));
$resultRows = $this->fetchAll($select);
}
但是我收到此错误:SQLSTATE [42000]:语法错误或访问冲突:1064您的SQL语法中有错误;查看与您的MySQL服务器版本相对应的手册,以获得在''附近使用的正确语法。在第1行,查询是:SELECT articles
。* FROM articles
WHERE(
谢谢你的帮助
答案 0 :(得分:0)
应用程序显示可以编辑的每个页面的页面名称。点击"编辑"它显示可以编辑,删除的文章 这是Articlemodel的所有代码
类Application_Model_DbTable_Articles扩展了Zend_Db_Table_Abstract {
protected $_name = 'articles';
public function __construct(){
parent::__construct();
}
public function getPagearticle(){
$db = Zend_Db_Table::getDefaultAdapter();
$select = new Zend_Db_Select($db);
$select = $db->select()
->from(array('a' => 'articles'), array('page_id', 'Nom_article'))
->join(array('p' => 'pages'), 'p.id = a.page_id',array('p.nom'));
$resultRows = $this->fetchAll($select);
}
public function getArticle($id)
{
$id = (int)$id;
$row = $this->fetchRow('id = ' . $id);
if (!$row) {
throw new Exception("Could not find row $id");
}
return $row->toArray();
}
public function addArticle($Nom_article, $description,$Img,$date, $Contenue,$is_show)
{
$data = array(
'Nom_article' => $Nom_article,
'description' => $description,
'Img' => $Img,
'date'=>$date,
'Contenue' => $Contenue,
'is_show'=> $is_show
);
$this->insert($data);
}
public function updateArticle($id,$Nom_article, $description,$Img,$date, $Contenue,$is_show)
{
$data = array(
'Nom_article' => $Nom_article,
'description' => $description,
'Img' => $Img,
'date'=>$date,
'Contenue' => $Contenue,
'is_show'=> $is_show
);
$this->update($data, 'id = '. (int)$id);
}
public function deleteArticle($id)
{
$this->delete('id =' . (int)$id);
}
}
答案 1 :(得分:-1)
实际上我从来没有在那种情况下使用过你的方法。
我在泛型:: getDefaultAdapter()中使用的只是一个纯文本查询,如
"SELECT page_id, nom_article FROM articles join ..."
我在表对象上构建选择
http://framework.zend.com/manual/1.10/en/zend.db.table.html
尝试使用
$resultRows = $db->fetchAll($select);
而不是你的$ this-> fetchAll($ select);