1

试图了解zf2。

我的代码:

$sql = new Sql($dbAdapter);

    $insert = $sql->insert('security');
    $insert->values(array(
            'user' => $userName,
            'ip' => '',
            'result' => 2
    ));
    $dbAdapter->query($insert->getSqlString(), $dbAdapter::QUERY_MODE_EXECUTE);

错误:

注意:尝试在没有特定驱动程序级别支持的情况下引用值可能会在生产环境中引入安全漏洞。在 /opt/projects/my/newSymbio/current/vendor/zendframework/zendframework/library/Zend/Db/Adapter/Platform/Sql92.php 第 80 行

有任何想法吗?

4

2 回答 2

0

我想通了。

$sql = new Sql($dbAdapter);

$insert = $sql->insert('security');
$insert->values(array(
        'user' => $userName,
        'ip' => '',
        'result' => 2
));
$statement = $sql->prepareStatementForSqlObject($insert);
$results = $statement->execute();
于 2013-08-08T09:53:50.343 回答
0

Here is the right syntax of insert in zf2:

   $data = array(
        ''user' => $userName,
        'ip' => '',
        'result' => '2'
    );

    $this->tableGateway->insert($data);

and you need to get the object of table in which table to want to insert the data.

Or another way as you are using is:

use Zend\Db\Sql\Sql;

Check you are using above line. And replace your last line with following code:

$selectString = $sql->getSqlStringForSqlObject($insert);
$results = $this->dbAdapter->query($selectString, $dbAdapter::QUERY_MODE_EXECUTE);

And I think you need to call change the $dbAdapter to $this->dbAdapter also try this.

于 2013-08-08T08:34:44.753 回答