PHP code example of sqltranslator / sql-translator
1. Go to this page and download the library: Download sqltranslator/sql-translator 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/ */
sqltranslator / sql-translator example snippets
$model = (new \SqlTranslator\Database())->config('mysql://root:#[email protected] :3306/demo')->pick('pdo');
$sql = $model->select()
->from(['a' => 'jst_book'], ['id', 'a.name', 'n' => '#NOW()'])
->joinLeft(['b' => 'jst_book_detail'], 'a.id = b.id', ['b.detail', 'b.cconte', 's' => '#NOW()'])
->where('a.id=1')->lock();
$result = $model->fetchAll($sql);
var_dump($result);exit;
exit;
$model = (new \SqlTranslator\Database())->config('mysql://root:#[email protected] :3306/demo')->pick('pdo');
$translator = new \SqlTranslator\SqlTranslator();
try {
$model->beginTransaction();
$sql = $model->select()
->from(['a' => 'jst_book'], ['id', 'a.name', 'n' => '#NOW()'])
->joinLeft(['b' => 'jst_book_detail'], 'a.id = b.id', ['b.detail', 'b.cconte', 's' => '#NOW()'])
->where('a.id=1')->lock();
$result = $model->fetchAll($sql);
$model->commit();
return $oid;
} catch (\Exception $e) {
$model->rollBack();
return false;
}
var_dump($result);exit;
exit;
$insert = $model->insert()
->into(
'table', [
'name',
'phone',
'type',
'price',
'price_type',
'order_count',
]
)
->values(
[
$params['name'],
$params['phone'],
$params['type'],
(float)$params['price'],
$params['price_type'],
0,
]
)
->duplicate(['order_count' => 1, 'name' => $params['name']]);
$result = $model->query($sql);
exit;
$update = $this->_db_translator->update
->set($classname::tableName(), $params)
->where('id=?', $id);
$delete = $model->delete()
->from('table')
->where('id=?', $id);