2020-03-02 16:14:20 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace ZM\DB;
|
|
|
|
|
|
|
|
|
|
|
2020-04-29 15:29:56 +08:00
|
|
|
use ZM\Exception\DbException;
|
|
|
|
|
|
2020-03-02 16:14:20 +08:00
|
|
|
class InsertBody
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* @var Table
|
|
|
|
|
*/
|
|
|
|
|
private $table;
|
|
|
|
|
private $row;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* InsertBody constructor.
|
|
|
|
|
* @param Table $table
|
|
|
|
|
* @param $row
|
|
|
|
|
*/
|
|
|
|
|
public function __construct(Table $table, $row) {
|
|
|
|
|
$this->table = $table;
|
|
|
|
|
$this->row = $row;
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-29 15:29:56 +08:00
|
|
|
/**
|
|
|
|
|
* @throws DbException
|
|
|
|
|
*/
|
2020-03-02 16:14:20 +08:00
|
|
|
public function save() {
|
2020-04-26 15:01:18 +08:00
|
|
|
DB::rawQuery('INSERT INTO ' . $this->table->getTableName() . ' VALUES ('.implode(',', array_fill(0, count($this->row), '?')).')', $this->row);
|
2020-03-02 16:14:20 +08:00
|
|
|
}
|
2020-04-26 15:01:18 +08:00
|
|
|
}
|