PHP code example of flyokai / zend-db-sql-insertmultiple

1. Go to this page and download the library: Download flyokai/zend-db-sql-insertmultiple library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

flyokai / zend-db-sql-insertmultiple example snippets


use Laminas\Db\Sql\InsertMultiple;
use Laminas\Db\Sql\Sql;

$insert = new InsertMultiple('users');
$insert->columns(['email', 'name', 'status']);
$insert->values([
    ['[email protected]', 'Alice', 1],
    ['[email protected]',   'Bob',   0],
]);

$sql = new Sql($adapter);
$stmt = $sql->prepareStatementForSqlObject($insert);
$stmt->execute();

// → INSERT INTO users (email, name, status) VALUES (?, ?, ?), (?, ?, ?)

$insert = new InsertMultiple('users');
$insert->columns(['email', 'name']);
$insert->select(
    $sql->select('staging_users')->columns(['email', 'name'])
);

// → INSERT INTO users (email, name) SELECT email, name FROM staging_users

$insert->values([['[email protected]', 'A']]);                                   // sets the rows
$insert->values(['[email protected]', 'C'], InsertMultiple::VALUES_MERGE);       // appends a row