Source of file Insert.php
Size: 1,540 Bytes - Last Modified: 2017-11-08T13:54:24+00:00
/home/travis/build/bluzphp/framework/src/Db/Query/Insert.php
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 | <?php /** * Bluz Framework Component * * @copyright Bluz PHP Team * @link https://github.com/bluzphp/framework */ declare(strict_types=1); namespace Bluz\Db\Query; use Bluz\Proxy\Db; /** * Builder of INSERT queries * * @package Bluz\Db\Query */ class Insert extends AbstractBuilder { use Traits\Set; /** * {@inheritdoc} * * @param null $sequence * * @return integer|string|array */ public function execute($sequence = null) { $result = Db::query($this->getSql(), $this->params, $this->types); if ($result) { return Db::handler()->lastInsertId($sequence); } return $result; } /** * {@inheritdoc} * * @return string */ public function getSql() : string { $query = "INSERT" . " INTO " . $this->sqlParts['from']['table'] . " SET " . implode(", ", $this->sqlParts['set']); return $query; } /** * Turns the query being built into an insert query that inserts into * a certain table * * Example * <code> * $ib = new InsertBuilder(); * $ib * ->insert('users') * ->set('name', 'username') * ->set('password', md5('password')); * </code> * * @param string $table The table into which the rows should be inserted * * @return Insert instance */ public function insert($table) { return $this->setFromQueryPart($table); } } |