Hello is there any way to insert data in a db table using the zf1 style on zf2?
$db->insert('tablename', $data);
where $data
is an associative array contains (columns, values)
thanks
To make an insert in zf2:
use Zend\Db\Sql\Sql;
$sql = new Sql($this->dbAdapter);
$insert = $sql->insert('table');
$newData = array(
'col1'=> 'val1',
'col2'=> 'val2',
'col3'=> 'val3'
);
$insert->values($newData);
$selectString = $sql->getSqlStringForSqlObject($insert);
$results = $this->dbAdapter->query($selectString, Adapter::QUERY_MODE_EXECUTE);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With