1
votes

trying to understand zf2.

my code:

$sql = new Sql($dbAdapter);

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

error:

Notice: Attempting to quote a value without specific driver level support can introduce security vulnerabilities in a production environment. in /opt/projects/my/newSymbio/current/vendor/zendframework/zendframework/library/Zend/Db/Adapter/Platform/Sql92.php on line 80

any ideas?

2

2 Answers

0
votes

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.

0
votes

i figure it out.

$sql = new Sql($dbAdapter);

$insert = $sql->insert('security');
$insert->values(array(
        'user' => $userName,
        'ip' => '',
        'result' => 2
));
$statement = $sql->prepareStatementForSqlObject($insert);
$results = $statement->execute();