__construct() public method

Sql constructor.
public __construct ( string $sql, integer | int[] $errorCodesToIgnore )
$sql string
$errorCodesToIgnore integer | int[] If no error should be ignored use an empty array.
Example #1
0
 /**
  * Constructor.
  * @param Db\Settings $dbSettings
  * @param string $table Prefixed table name
  * @param string|string[] $columnNames array(columnName => columnValue)
  * @param string|string[] $primaryKey one or multiple columns that define the primary key
  */
 public function __construct(Db\Settings $dbSettings, $table, $columnNames, $primaryKey)
 {
     $columns = array();
     foreach ($columnNames as $column => $type) {
         $columns[] = sprintf('`%s` %s', $column, $type);
     }
     if (!empty($primaryKey)) {
         $columns[] = sprintf('PRIMARY KEY ( `%s` )', implode('`, `', $primaryKey));
     }
     $sql = sprintf('CREATE TABLE `%s` (%s) ENGINE=%s DEFAULT CHARSET=utf8', $table, implode(', ', $columns), $dbSettings->getEngine());
     parent::__construct($sql, static::ERROR_CODE_TABLE_EXISTS);
 }
Example #2
0
 /**
  * @param string $table Prefixed table name
  * @param string $indexName name of the index
  */
 public function __construct($table, $indexName)
 {
     $sql = sprintf('ALTER TABLE `%s` DROP INDEX `%s`', $table, $indexName);
     parent::__construct($sql, array(static::ERROR_CODE_COLUMN_NOT_EXISTS));
 }
Example #3
0
 /**
  * @param string $table Prefixed table name
  */
 public function __construct($table)
 {
     $sql = sprintf('DROP TABLE IF EXISTS `%s`', $table);
     parent::__construct($sql, array(static::ERROR_CODE_TABLE_NOT_EXISTS, static::ERROR_CODE_UNKNOWN_TABLE));
 }
Example #4
0
 /**
  * BoundSql constructor.
  * @param string $sql
  * @param array $bind
  * @param int|int[] $errorCodesToIgnore
  */
 public function __construct($sql, $bind, $errorCodesToIgnore)
 {
     parent::__construct($sql, $errorCodesToIgnore);
     $this->bind = (array) $bind;
 }