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
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);
My proposition using TableGateway:
$adapter = $this->tableGateway->getAdapter();
$otherTable = new Zend\Db\TableGateway\TableGateway('table_name', $adapter);
$otherTable->insert($data));