Zend Framework 2插入数据库工作正常,但仍然出现错误

时间:2013-07-24 06:27:06

标签: php zend-framework zend-framework2 zend-db zend-db-table

以下是我的型号代码,

public function insertme()
{
    $sel = new Sql($this->adapter);
    $s = $sel->insert('users');
    $data = array(
            'fname'=>'fisdsds',
            'lname'=>'sdsdsdme',
            'email'=>'sdsdsds',
            'pword'=>'dsdsds'

    );
    $s->values($data);
    $statement = $sel->prepareStatementForSqlObject($s);
    $comments = $statement->execute();      
    $resultset = new ResultSet();
    $resultset->initialize($comments);
    $result = $resultset->toArray();
    //print_R($result);
    return $result;

}

它正在将数据插入数据库表users,但我也收到错误SQLSTATE[HY000]: General error可能是什么问题?

1 个答案:

答案 0 :(得分:1)

没有必要尝试从插入中创建ResultSet,它不会返回任何结果集数据。

public function insertme()
{
    $sel = new Sql($this->adapter);
    $s = $sel->insert('users');
    $data = array(
            'fname'=>'fisdsds',
            'lname'=>'sdsdsdme',
            'email'=>'sdsdsds',
            'pword'=>'dsdsds'

    );
    $s->values($data);
    $statement = $sel->prepareStatementForSqlObject($s);
    $result= $statement->execute();      
    //print_R($result);

    return $result;
}