PHP code example of aymanelarian / import-query-generator-pg
1. Go to this page and download the library: Download aymanelarian/import-query-generator-pg 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/ */
aymanelarian / import-query-generator-pg example snippets
use AymanElarian\QueryGenerator;
$table = 'users';
$data = [
['name' => 'John', 'email' => '[email protected]', 'password' => 'hashed_password', 'created_at' => date('Y-m-d'), 'updated_at' => date('Y-m-d')],
['name' => 'Jane', 'email' => '[email protected]', 'password' => 'hashed_password', 'created_at' => date('Y-m-d'), 'updated_at' => date('Y-m-d')],
['name' => 'Susy', 'email' => '[email protected]', 'password' => 'hashed_password', 'created_at' => date('Y-m-d'), 'updated_at' => date('Y-m-d')],
];
$excludedColumnsFromUpdate = ['password', 'created_at'];
$queryObject = (new QueryGenerator)->generate($table, $data, $excludedColumnsFromUpdate);
$queryObject->getQuery();
// -> "insert into `users` (`name`,`email`,`password`,`created_at`,`updated_at`) values (?,?,?,?,?),(?,?,?,?,?),(?,?,?,?,?) on duplicate key update `name`=VALUES(`name`),`email`=VALUES(`email`),`updated_at`=VALUES(`updated_at`)"
$queryObject->getBindings();
// -> ['John', '[email protected]', 'hashed_password', '2018-01-12', '2018-01-12', 'Jane', '[email protected]', 'hashed_password', '2018-01-12', '2018-01-12', 'Susy', '[email protected]', 'hashed_password', '2018-01-12', '2018-01-12']