code
stringlengths 17
296k
| docstring
stringlengths 30
30.3k
| func_name
stringlengths 1
89
| language
stringclasses 1
value | repo
stringlengths 7
63
| path
stringlengths 7
153
| url
stringlengths 51
209
| license
stringclasses 4
values |
---|---|---|---|---|---|---|---|
public function cancel()
{
$this->_statement=null;
} | Cancels the execution of the SQL statement. | cancel | php | yiisoft/yii | framework/db/CDbCommand.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbCommand.php | BSD-3-Clause |
public function bindParam($name, &$value, $dataType=null, $length=null, $driverOptions=null)
{
$this->prepare();
if($dataType===null)
$this->_statement->bindParam($name,$value,$this->_connection->getPdoType(gettype($value)));
elseif($length===null)
$this->_statement->bindParam($name,$value,$dataType);
elseif($driverOptions===null)
$this->_statement->bindParam($name,$value,$dataType,$length);
else
$this->_statement->bindParam($name,$value,$dataType,$length,$driverOptions);
$this->_paramLog[$name]=&$value;
return $this;
} | Binds a parameter to the SQL statement to be executed.
@param mixed $name Parameter identifier. For a prepared statement
using named placeholders, this will be a parameter name of
the form :name. For a prepared statement using question mark
placeholders, this will be the 1-indexed position of the parameter.
@param mixed $value Name of the PHP variable to bind to the SQL statement parameter
@param integer $dataType SQL data type of the parameter. If null, the type is determined by the PHP type of the value.
@param integer $length length of the data type
@param mixed $driverOptions the driver-specific options (this is available since version 1.1.6)
@return static the current command being executed
@see https://www.php.net/manual/en/function.PDOStatement-bindParam.php | bindParam | php | yiisoft/yii | framework/db/CDbCommand.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbCommand.php | BSD-3-Clause |
public function bindValue($name, $value, $dataType=null)
{
$this->prepare();
if($dataType===null)
$this->_statement->bindValue($name,$value,$this->_connection->getPdoType(gettype($value)));
else
$this->_statement->bindValue($name,$value,$dataType);
$this->_paramLog[$name]=$value;
return $this;
} | Binds a value to a parameter.
@param mixed $name Parameter identifier. For a prepared statement
using named placeholders, this will be a parameter name of
the form :name. For a prepared statement using question mark
placeholders, this will be the 1-indexed position of the parameter.
@param mixed $value The value to bind to the parameter
@param integer $dataType SQL data type of the parameter. If null, the type is determined by the PHP type of the value.
@return static the current command being executed
@see https://www.php.net/manual/en/function.PDOStatement-bindValue.php | bindValue | php | yiisoft/yii | framework/db/CDbCommand.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbCommand.php | BSD-3-Clause |
public function getSelect()
{
return isset($this->_query['select']) ? $this->_query['select'] : '';
} | Returns the SELECT part in the query.
@return string the SELECT part (without 'SELECT') in the query.
@since 1.1.6 | getSelect | php | yiisoft/yii | framework/db/CDbCommand.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbCommand.php | BSD-3-Clause |
public function setSelect($value)
{
$this->select($value);
} | Sets the SELECT part in the query.
@param mixed $value the data to be selected. Please refer to {@link select()} for details
on how to specify this parameter.
@since 1.1.6 | setSelect | php | yiisoft/yii | framework/db/CDbCommand.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbCommand.php | BSD-3-Clause |
public function selectDistinct($columns='*')
{
$this->_query['distinct']=true;
return $this->select($columns);
} | Sets the SELECT part of the query with the DISTINCT flag turned on.
This is the same as {@link select} except that the DISTINCT flag is turned on.
@param mixed $columns the columns to be selected. See {@link select} for more details.
@return CDbCommand the command object itself
@since 1.1.6 | selectDistinct | php | yiisoft/yii | framework/db/CDbCommand.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbCommand.php | BSD-3-Clause |
public function getDistinct()
{
return isset($this->_query['distinct']) ? $this->_query['distinct'] : false;
} | Returns a value indicating whether SELECT DISTINCT should be used.
@return boolean a value indicating whether SELECT DISTINCT should be used.
@since 1.1.6 | getDistinct | php | yiisoft/yii | framework/db/CDbCommand.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbCommand.php | BSD-3-Clause |
public function setDistinct($value)
{
$this->_query['distinct']=$value;
} | Sets a value indicating whether SELECT DISTINCT should be used.
@param boolean $value a value indicating whether SELECT DISTINCT should be used.
@since 1.1.6 | setDistinct | php | yiisoft/yii | framework/db/CDbCommand.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbCommand.php | BSD-3-Clause |
public function from($tables)
{
if(is_string($tables) && strpos($tables,'(')!==false)
$this->_query['from']=$tables;
else
{
if(!is_array($tables))
$tables=preg_split('/\s*,\s*/',trim($tables),-1,PREG_SPLIT_NO_EMPTY);
foreach($tables as $i=>$table)
{
if(strpos($table,'(')===false)
{
if(preg_match('/^(.*?)(?i:\s+as|)\s+([^ ]+)$/',$table,$matches)) // with alias
$tables[$i]=$this->_connection->quoteTableName($matches[1]).' '.$this->_connection->quoteTableName($matches[2]);
else
$tables[$i]=$this->_connection->quoteTableName($table);
}
}
$this->_query['from']=implode(', ',$tables);
}
return $this;
} | Sets the FROM part of the query.
@param mixed $tables the table(s) to be selected from. This can be either a string (e.g. 'tbl_user')
or an array (e.g. array('tbl_user', 'tbl_profile')) specifying one or several table names.
Table names can contain schema prefixes (e.g. 'public.tbl_user') and/or table aliases (e.g. 'tbl_user u').
The method will automatically quote the table names unless it contains some parenthesis
(which means the table is given as a sub-query or DB expression).
@return static the command object itself
@since 1.1.6 | from | php | yiisoft/yii | framework/db/CDbCommand.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbCommand.php | BSD-3-Clause |
public function getFrom()
{
return isset($this->_query['from']) ? $this->_query['from'] : '';
} | Returns the FROM part in the query.
@return string the FROM part (without 'FROM' ) in the query.
@since 1.1.6 | getFrom | php | yiisoft/yii | framework/db/CDbCommand.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbCommand.php | BSD-3-Clause |
public function setFrom($value)
{
$this->from($value);
} | Sets the FROM part in the query.
@param mixed $value the tables to be selected from. Please refer to {@link from()} for details
on how to specify this parameter.
@since 1.1.6 | setFrom | php | yiisoft/yii | framework/db/CDbCommand.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbCommand.php | BSD-3-Clause |
public function getWhere()
{
return isset($this->_query['where']) ? $this->_query['where'] : '';
} | Returns the WHERE part in the query.
@return string the WHERE part (without 'WHERE' ) in the query.
@since 1.1.6 | getWhere | php | yiisoft/yii | framework/db/CDbCommand.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbCommand.php | BSD-3-Clause |
public function setWhere($value)
{
$this->where($value);
} | Sets the WHERE part in the query.
@param mixed $value the where part. Please refer to {@link where()} for details
on how to specify this parameter.
@since 1.1.6 | setWhere | php | yiisoft/yii | framework/db/CDbCommand.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbCommand.php | BSD-3-Clause |
public function getJoin()
{
return isset($this->_query['join']) ? $this->_query['join'] : '';
} | Returns the join part in the query.
@return mixed the join part in the query. This can be an array representing
multiple join fragments, or a string representing a single join fragment.
Each join fragment will contain the proper join operator (e.g. LEFT JOIN).
@since 1.1.6 | getJoin | php | yiisoft/yii | framework/db/CDbCommand.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbCommand.php | BSD-3-Clause |
public function setJoin($value)
{
$this->_query['join']=$value;
} | Sets the join part in the query.
@param mixed $value the join part in the query. This can be either a string or
an array representing multiple join parts in the query. Each part must contain
the proper join operator (e.g. 'LEFT JOIN tbl_profile ON tbl_user.id=tbl_profile.id')
@since 1.1.6 | setJoin | php | yiisoft/yii | framework/db/CDbCommand.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbCommand.php | BSD-3-Clause |
public function crossJoin($table)
{
return $this->joinInternal('cross join', $table);
} | Appends a CROSS JOIN part to the query.
Note that not all DBMS support CROSS JOIN.
@param string $table the table to be joined.
Table name can contain schema prefix (e.g. 'public.tbl_user') and/or table alias (e.g. 'tbl_user u').
The method will automatically quote the table name unless it contains some parenthesis
(which means the table is given as a sub-query or DB expression).
@return CDbCommand the command object itself
@since 1.1.6 | crossJoin | php | yiisoft/yii | framework/db/CDbCommand.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbCommand.php | BSD-3-Clause |
public function naturalJoin($table)
{
return $this->joinInternal('natural join', $table);
} | Appends a NATURAL JOIN part to the query.
Note that not all DBMS support NATURAL JOIN.
@param string $table the table to be joined.
Table name can contain schema prefix (e.g. 'public.tbl_user') and/or table alias (e.g. 'tbl_user u').
The method will automatically quote the table name unless it contains some parenthesis
(which means the table is given as a sub-query or DB expression).
@return CDbCommand the command object itself
@since 1.1.6 | naturalJoin | php | yiisoft/yii | framework/db/CDbCommand.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbCommand.php | BSD-3-Clause |
public function naturalLeftJoin($table)
{
return $this->joinInternal('natural left join', $table);
} | Appends a NATURAL LEFT JOIN part to the query.
Note that not all DBMS support NATURAL LEFT JOIN.
@param string $table the table to be joined.
Table name can contain schema prefix (e.g. 'public.tbl_user') and/or table alias (e.g. 'tbl_user u').
The method will automatically quote the table name unless it contains some parenthesis
(which means the table is given as a sub-query or DB expression).
@return CDbCommand the command object itself
@since 1.1.16 | naturalLeftJoin | php | yiisoft/yii | framework/db/CDbCommand.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbCommand.php | BSD-3-Clause |
public function naturalRightJoin($table)
{
return $this->joinInternal('natural right join', $table);
} | Appends a NATURAL RIGHT JOIN part to the query.
Note that not all DBMS support NATURAL RIGHT JOIN.
@param string $table the table to be joined.
Table name can contain schema prefix (e.g. 'public.tbl_user') and/or table alias (e.g. 'tbl_user u').
The method will automatically quote the table name unless it contains some parenthesis
(which means the table is given as a sub-query or DB expression).
@return CDbCommand the command object itself
@since 1.1.16 | naturalRightJoin | php | yiisoft/yii | framework/db/CDbCommand.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbCommand.php | BSD-3-Clause |
public function getGroup()
{
return isset($this->_query['group']) ? $this->_query['group'] : '';
} | Returns the GROUP BY part in the query.
@return string the GROUP BY part (without 'GROUP BY' ) in the query.
@since 1.1.6 | getGroup | php | yiisoft/yii | framework/db/CDbCommand.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbCommand.php | BSD-3-Clause |
public function setGroup($value)
{
$this->group($value);
} | Sets the GROUP BY part in the query.
@param mixed $value the GROUP BY part. Please refer to {@link group()} for details
on how to specify this parameter.
@since 1.1.6 | setGroup | php | yiisoft/yii | framework/db/CDbCommand.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbCommand.php | BSD-3-Clause |
public function getHaving()
{
return isset($this->_query['having']) ? $this->_query['having'] : '';
} | Returns the HAVING part in the query.
@return string the HAVING part (without 'HAVING' ) in the query.
@since 1.1.6 | getHaving | php | yiisoft/yii | framework/db/CDbCommand.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbCommand.php | BSD-3-Clause |
public function setHaving($value)
{
$this->having($value);
} | Sets the HAVING part in the query.
@param mixed $value the HAVING part. Please refer to {@link having()} for details
on how to specify this parameter.
@since 1.1.6 | setHaving | php | yiisoft/yii | framework/db/CDbCommand.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbCommand.php | BSD-3-Clause |
public function getOrder()
{
return isset($this->_query['order']) ? $this->_query['order'] : '';
} | Returns the ORDER BY part in the query.
@return string the ORDER BY part (without 'ORDER BY' ) in the query.
@since 1.1.6 | getOrder | php | yiisoft/yii | framework/db/CDbCommand.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbCommand.php | BSD-3-Clause |
public function setOrder($value)
{
$this->order($value);
} | Sets the ORDER BY part in the query.
@param mixed $value the ORDER BY part. Please refer to {@link order()} for details
on how to specify this parameter.
@since 1.1.6 | setOrder | php | yiisoft/yii | framework/db/CDbCommand.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbCommand.php | BSD-3-Clause |
public function limit($limit, $offset=null)
{
$this->_query['limit']=(int)$limit;
if($offset!==null)
$this->offset($offset);
return $this;
} | Sets the LIMIT part of the query.
@param integer $limit the limit
@param integer $offset the offset
@return static the command object itself
@since 1.1.6 | limit | php | yiisoft/yii | framework/db/CDbCommand.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbCommand.php | BSD-3-Clause |
public function getLimit()
{
return isset($this->_query['limit']) ? $this->_query['limit'] : -1;
} | Returns the LIMIT part in the query.
@return string the LIMIT part (without 'LIMIT' ) in the query.
@since 1.1.6 | getLimit | php | yiisoft/yii | framework/db/CDbCommand.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbCommand.php | BSD-3-Clause |
public function setLimit($value)
{
$this->limit($value);
} | Sets the LIMIT part in the query.
@param integer $value the LIMIT part. Please refer to {@link limit()} for details
on how to specify this parameter.
@since 1.1.6 | setLimit | php | yiisoft/yii | framework/db/CDbCommand.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbCommand.php | BSD-3-Clause |
public function offset($offset)
{
$this->_query['offset']=(int)$offset;
return $this;
} | Sets the OFFSET part of the query.
@param integer $offset the offset
@return static the command object itself
@since 1.1.6 | offset | php | yiisoft/yii | framework/db/CDbCommand.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbCommand.php | BSD-3-Clause |
public function getOffset()
{
return isset($this->_query['offset']) ? $this->_query['offset'] : -1;
} | Returns the OFFSET part in the query.
@return string the OFFSET part (without 'OFFSET' ) in the query.
@since 1.1.6 | getOffset | php | yiisoft/yii | framework/db/CDbCommand.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbCommand.php | BSD-3-Clause |
public function setOffset($value)
{
$this->offset($value);
} | Sets the OFFSET part in the query.
@param integer $value the OFFSET part. Please refer to {@link offset()} for details
on how to specify this parameter.
@since 1.1.6 | setOffset | php | yiisoft/yii | framework/db/CDbCommand.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbCommand.php | BSD-3-Clause |
public function union($sql)
{
if(isset($this->_query['union']) && is_string($this->_query['union']))
$this->_query['union']=array($this->_query['union']);
$this->_query['union'][]=$sql;
return $this;
} | Appends a SQL statement using UNION operator.
@param string $sql the SQL statement to be appended using UNION
@return static the command object itself
@since 1.1.6 | union | php | yiisoft/yii | framework/db/CDbCommand.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbCommand.php | BSD-3-Clause |
public function getUnion()
{
return isset($this->_query['union']) ? $this->_query['union'] : '';
} | Returns the UNION part in the query.
@return mixed the UNION part (without 'UNION' ) in the query.
This can be either a string or an array representing multiple union parts.
@since 1.1.6 | getUnion | php | yiisoft/yii | framework/db/CDbCommand.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbCommand.php | BSD-3-Clause |
public function setUnion($value)
{
$this->_query['union']=$value;
} | Sets the UNION part in the query.
@param mixed $value the UNION part. This can be either a string or an array
representing multiple SQL statements to be unioned together.
@since 1.1.6 | setUnion | php | yiisoft/yii | framework/db/CDbCommand.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbCommand.php | BSD-3-Clause |
public function createTable($table, $columns, $options=null)
{
return $this->setText($this->getConnection()->getSchema()->createTable($table, $columns, $options))->execute();
} | Builds and executes a SQL statement for creating a new DB table.
The columns in the new table should be specified as name-definition pairs (e.g. 'name'=>'string'),
where name stands for a column name which will be properly quoted by the method, and definition
stands for the column type which can contain an abstract DB type.
The {@link getColumnType} method will be invoked to convert any abstract type into a physical one.
If a column is specified with definition only (e.g. 'PRIMARY KEY (name, type)'), it will be directly
inserted into the generated SQL.
@param string $table the name of the table to be created. The name will be properly quoted by the method.
@param array $columns the columns (name=>definition) in the new table.
@param string $options additional SQL fragment that will be appended to the generated SQL.
@return integer 0 is always returned. See {@link https://php.net/manual/en/pdostatement.rowcount.php} for more information.
@since 1.1.6 | createTable | php | yiisoft/yii | framework/db/CDbCommand.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbCommand.php | BSD-3-Clause |
public function renameTable($table, $newName)
{
return $this->setText($this->getConnection()->getSchema()->renameTable($table, $newName))->execute();
} | Builds and executes a SQL statement for renaming a DB table.
@param string $table the table to be renamed. The name will be properly quoted by the method.
@param string $newName the new table name. The name will be properly quoted by the method.
@return integer 0 is always returned. See {@link https://php.net/manual/en/pdostatement.rowcount.php} for more information.
@since 1.1.6 | renameTable | php | yiisoft/yii | framework/db/CDbCommand.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbCommand.php | BSD-3-Clause |
public function dropTable($table)
{
return $this->setText($this->getConnection()->getSchema()->dropTable($table))->execute();
} | Builds and executes a SQL statement for dropping a DB table.
@param string $table the table to be dropped. The name will be properly quoted by the method.
@return integer 0 is always returned. See {@link https://php.net/manual/en/pdostatement.rowcount.php} for more information.
@since 1.1.6 | dropTable | php | yiisoft/yii | framework/db/CDbCommand.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbCommand.php | BSD-3-Clause |
public function truncateTable($table)
{
$schema=$this->getConnection()->getSchema();
$n=$this->setText($schema->truncateTable($table))->execute();
if(strncasecmp($this->getConnection()->getDriverName(),'sqlite',6)===0)
$schema->resetSequence($schema->getTable($table));
return $n;
} | Builds and executes a SQL statement for truncating a DB table.
@param string $table the table to be truncated. The name will be properly quoted by the method.
@return integer number of rows affected by the execution.
@since 1.1.6 | truncateTable | php | yiisoft/yii | framework/db/CDbCommand.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbCommand.php | BSD-3-Clause |
public function addColumn($table, $column, $type)
{
return $this->setText($this->getConnection()->getSchema()->addColumn($table, $column, $type))->execute();
} | Builds and executes a SQL statement for adding a new DB column.
@param string $table the table that the new column will be added to. The table name will be properly quoted by the method.
@param string $column the name of the new column. The name will be properly quoted by the method.
@param string $type the column type. The {@link getColumnType} method will be invoked to convert abstract column type (if any)
into the physical one. Anything that is not recognized as abstract type will be kept in the generated SQL.
For example, 'string' will be turned into 'varchar(255)', while 'string not null' will become 'varchar(255) not null'.
@return integer number of rows affected by the execution.
@since 1.1.6 | addColumn | php | yiisoft/yii | framework/db/CDbCommand.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbCommand.php | BSD-3-Clause |
public function dropColumn($table, $column)
{
return $this->setText($this->getConnection()->getSchema()->dropColumn($table, $column))->execute();
} | Builds and executes a SQL statement for dropping a DB column.
@param string $table the table whose column is to be dropped. The name will be properly quoted by the method.
@param string $column the name of the column to be dropped. The name will be properly quoted by the method.
@return integer number of rows affected by the execution.
@since 1.1.6 | dropColumn | php | yiisoft/yii | framework/db/CDbCommand.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbCommand.php | BSD-3-Clause |
public function renameColumn($table, $name, $newName)
{
return $this->setText($this->getConnection()->getSchema()->renameColumn($table, $name, $newName))->execute();
} | Builds and executes a SQL statement for renaming a column.
@param string $table the table whose column is to be renamed. The name will be properly quoted by the method.
@param string $name the old name of the column. The name will be properly quoted by the method.
@param string $newName the new name of the column. The name will be properly quoted by the method.
@return integer number of rows affected by the execution.
@since 1.1.6 | renameColumn | php | yiisoft/yii | framework/db/CDbCommand.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbCommand.php | BSD-3-Clause |
public function alterColumn($table, $column, $type)
{
return $this->setText($this->getConnection()->getSchema()->alterColumn($table, $column, $type))->execute();
} | Builds and executes a SQL statement for changing the definition of a column.
@param string $table the table whose column is to be changed. The table name will be properly quoted by the method.
@param string $column the name of the column to be changed. The name will be properly quoted by the method.
@param string $type the new column type. The {@link getColumnType} method will be invoked to convert abstract column type (if any)
into the physical one. Anything that is not recognized as abstract type will be kept in the generated SQL.
For example, 'string' will be turned into 'varchar(255)', while 'string not null' will become 'varchar(255) not null'.
@return integer number of rows affected by the execution.
@since 1.1.6 | alterColumn | php | yiisoft/yii | framework/db/CDbCommand.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbCommand.php | BSD-3-Clause |
public function addForeignKey($name, $table, $columns, $refTable, $refColumns, $delete=null, $update=null)
{
return $this->setText($this->getConnection()->getSchema()->addForeignKey($name, $table, $columns, $refTable, $refColumns, $delete, $update))->execute();
} | Builds a SQL statement for adding a foreign key constraint to an existing table.
The method will properly quote the table and column names.
@param string $name the name of the foreign key constraint.
@param string $table the table that the foreign key constraint will be added to.
@param string|array $columns the name of the column to that the constraint will be added on. If there are multiple columns, separate them with commas or pass as an array of column names.
@param string $refTable the table that the foreign key references to.
@param string|array $refColumns the name of the column that the foreign key references to. If there are multiple columns, separate them with commas or pass as an array of column names.
@param string $delete the ON DELETE option. Most DBMS support these options: RESTRICT, CASCADE, NO ACTION, SET DEFAULT, SET NULL
@param string $update the ON UPDATE option. Most DBMS support these options: RESTRICT, CASCADE, NO ACTION, SET DEFAULT, SET NULL
@return integer number of rows affected by the execution.
@since 1.1.6 | addForeignKey | php | yiisoft/yii | framework/db/CDbCommand.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbCommand.php | BSD-3-Clause |
public function dropForeignKey($name, $table)
{
return $this->setText($this->getConnection()->getSchema()->dropForeignKey($name, $table))->execute();
} | Builds a SQL statement for dropping a foreign key constraint.
@param string $name the name of the foreign key constraint to be dropped. The name will be properly quoted by the method.
@param string $table the table whose foreign is to be dropped. The name will be properly quoted by the method.
@return integer number of rows affected by the execution.
@since 1.1.6 | dropForeignKey | php | yiisoft/yii | framework/db/CDbCommand.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbCommand.php | BSD-3-Clause |
public function createIndex($name, $table, $columns, $unique=false)
{
return $this->setText($this->getConnection()->getSchema()->createIndex($name, $table, $columns, $unique))->execute();
} | Builds and executes a SQL statement for creating a new index.
@param string $name the name of the index. The name will be properly quoted by the method.
@param string $table the table that the new index will be created for. The table name will be properly quoted by the method.
@param string|array $columns the column(s) that should be included in the index. If there are multiple columns, please separate them
by commas or pass as an array of column names. Each column name will be properly quoted by the method, unless a parenthesis is found in the name.
@param boolean $unique whether to add UNIQUE constraint on the created index.
@return integer number of rows affected by the execution.
@since 1.1.6 | createIndex | php | yiisoft/yii | framework/db/CDbCommand.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbCommand.php | BSD-3-Clause |
public function dropIndex($name, $table)
{
return $this->setText($this->getConnection()->getSchema()->dropIndex($name, $table))->execute();
} | Builds and executes a SQL statement for dropping an index.
@param string $name the name of the index to be dropped. The name will be properly quoted by the method.
@param string $table the table whose index is to be dropped. The name will be properly quoted by the method.
@return integer number of rows affected by the execution.
@since 1.1.6 | dropIndex | php | yiisoft/yii | framework/db/CDbCommand.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbCommand.php | BSD-3-Clause |
public function addPrimaryKey($name,$table,$columns)
{
return $this->setText($this->getConnection()->getSchema()->addPrimaryKey($name,$table,$columns))->execute();
} | Builds a SQL statement for creating a primary key constraint.
@param string $name the name of the primary key constraint to be created. The name will be properly quoted by the method.
@param string $table the table who will be inheriting the primary key. The name will be properly quoted by the method.
@param string|array $columns comma separated string or array of columns that the primary key will consist of.
Array value can be passed since 1.1.14.
@return integer number of rows affected by the execution.
@since 1.1.13 | addPrimaryKey | php | yiisoft/yii | framework/db/CDbCommand.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbCommand.php | BSD-3-Clause |
public function dropPrimaryKey($name,$table)
{
return $this->setText($this->getConnection()->getSchema()->dropPrimaryKey($name,$table))->execute();
} | Builds a SQL statement for dropping a primary key constraint.
@param string $name the name of the primary key constraint to be dropped. The name will be properly quoted by the method.
@param string $table the table that owns the primary key. The name will be properly quoted by the method.
@return integer number of rows affected by the execution.
@since 1.1.13 | dropPrimaryKey | php | yiisoft/yii | framework/db/CDbCommand.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbCommand.php | BSD-3-Clause |
public function __construct($dsn='',$username='',$password='')
{
$this->connectionString=$dsn;
$this->username=$username;
$this->password=$password;
} | Constructor.
Note, the DB connection is not established when this connection
instance is created. Set {@link setActive active} property to true
to establish the connection.
@param string $dsn The Data Source Name, or DSN, contains the information required to connect to the database.
@param string $username The user name for the DSN string.
@param string $password The password for the DSN string.
@see https://www.php.net/manual/en/function.PDO-construct.php | __construct | php | yiisoft/yii | framework/db/CDbConnection.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbConnection.php | BSD-3-Clause |
public function __sleep()
{
$this->close();
return array_keys(get_object_vars($this));
} | Close the connection when serializing.
@return array | __sleep | php | yiisoft/yii | framework/db/CDbConnection.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbConnection.php | BSD-3-Clause |
public static function getAvailableDrivers()
{
return PDO::getAvailableDrivers();
} | Returns a list of available PDO drivers.
@return array list of available PDO drivers
@see https://www.php.net/manual/en/function.PDO-getAvailableDrivers.php | getAvailableDrivers | php | yiisoft/yii | framework/db/CDbConnection.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbConnection.php | BSD-3-Clause |
public function init()
{
parent::init();
if($this->autoConnect)
$this->setActive(true);
} | Initializes the component.
This method is required by {@link IApplicationComponent} and is invoked by application
when the CDbConnection is used as an application component.
If you override this method, make sure to call the parent implementation
so that the component can be marked as initialized. | init | php | yiisoft/yii | framework/db/CDbConnection.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbConnection.php | BSD-3-Clause |
public function getActive()
{
return $this->_active;
} | Returns whether the DB connection is established.
@return boolean whether the DB connection is established | getActive | php | yiisoft/yii | framework/db/CDbConnection.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbConnection.php | BSD-3-Clause |
public function setActive($value)
{
if($value!=$this->_active)
{
if($value)
$this->open();
else
$this->close();
}
} | Open or close the DB connection.
@param boolean $value whether to open or close DB connection
@throws CException if connection fails | setActive | php | yiisoft/yii | framework/db/CDbConnection.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbConnection.php | BSD-3-Clause |
public function cache($duration, $dependency=null, $queryCount=1)
{
$this->queryCachingDuration=$duration;
$this->queryCachingDependency=$dependency;
$this->queryCachingCount=$queryCount;
return $this;
} | Sets the parameters about query caching.
This method can be used to enable or disable query caching.
By setting the $duration parameter to be 0, the query caching will be disabled.
Otherwise, query results of the new SQL statements executed next will be saved in cache
and remain valid for the specified duration.
If the same query is executed again, the result may be fetched from cache directly
without actually executing the SQL statement.
@param integer $duration the number of seconds that query results may remain valid in cache.
If this is 0, the caching will be disabled.
@param CCacheDependency|ICacheDependency $dependency the dependency that will be used when saving
the query results into cache.
@param integer $queryCount number of SQL queries that need to be cached after calling this method. Defaults to 1,
meaning that the next SQL query will be cached.
@return static the connection instance itself.
@since 1.1.7 | cache | php | yiisoft/yii | framework/db/CDbConnection.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbConnection.php | BSD-3-Clause |
protected function open()
{
if($this->_pdo===null)
{
if(empty($this->connectionString))
throw new CDbException('CDbConnection.connectionString cannot be empty.');
try
{
Yii::trace('Opening DB connection','system.db.CDbConnection');
$this->_pdo=$this->createPdoInstance();
$this->initConnection($this->_pdo);
$this->_active=true;
}
catch(PDOException $e)
{
if(YII_DEBUG)
{
throw new CDbException('CDbConnection failed to open the DB connection: '.
$e->getMessage(),(int)$e->getCode(),$e->errorInfo);
}
else
{
Yii::log($e->getMessage(),CLogger::LEVEL_ERROR,'exception.CDbException');
throw new CDbException('CDbConnection failed to open the DB connection.',(int)$e->getCode(),$e->errorInfo);
}
}
}
} | Opens DB connection if it is currently not
@throws CException if connection fails | open | php | yiisoft/yii | framework/db/CDbConnection.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbConnection.php | BSD-3-Clause |
protected function close()
{
Yii::trace('Closing DB connection','system.db.CDbConnection');
$this->_pdo=null;
$this->_active=false;
$this->_schema=null;
} | Closes the currently active DB connection.
It does nothing if the connection is already closed. | close | php | yiisoft/yii | framework/db/CDbConnection.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbConnection.php | BSD-3-Clause |
protected function createPdoInstance()
{
$pdoClass=$this->pdoClass;
if(($driver=$this->getDriverName())!==null)
{
if($driver==='mssql' || $driver==='dblib')
$pdoClass='CMssqlPdoAdapter';
elseif($driver==='sqlsrv')
$pdoClass='CMssqlSqlsrvPdoAdapter';
}
if(!class_exists($pdoClass))
throw new CDbException(Yii::t('yii','CDbConnection is unable to find PDO class "{className}". Make sure PDO is installed correctly.',
array('{className}'=>$pdoClass)));
@$instance=new $pdoClass($this->connectionString,$this->username,$this->password,$this->_attributes);
if(!$instance)
throw new CDbException(Yii::t('yii','CDbConnection failed to open the DB connection.'));
return $instance;
} | Creates the PDO instance.
When some functionalities are missing in the pdo driver, we may use
an adapter class to provide them.
@throws CDbException when failed to open DB connection
@return PDO the pdo instance | createPdoInstance | php | yiisoft/yii | framework/db/CDbConnection.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbConnection.php | BSD-3-Clause |
protected function initConnection($pdo)
{
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
if($this->emulatePrepare!==null && constant('PDO::ATTR_EMULATE_PREPARES'))
$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES,$this->emulatePrepare);
if(PHP_VERSION_ID >= 80100 && strncasecmp($this->getDriverName(),'sqlite',6)===0)
$pdo->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true);
if($this->charset!==null)
{
$driver=strtolower($pdo->getAttribute(PDO::ATTR_DRIVER_NAME));
if(in_array($driver,array('pgsql','mysql','mysqli')))
$pdo->exec('SET NAMES '.$pdo->quote($this->charset));
}
if($this->initSQLs!==null)
{
foreach($this->initSQLs as $sql)
$pdo->exec($sql);
}
} | Initializes the open db connection.
This method is invoked right after the db connection is established.
The default implementation is to set the charset for MySQL, MariaDB and PostgreSQL database connections.
@param PDO $pdo the PDO instance | initConnection | php | yiisoft/yii | framework/db/CDbConnection.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbConnection.php | BSD-3-Clause |
public function getCurrentTransaction()
{
if($this->_transaction!==null)
{
if($this->_transaction->getActive())
return $this->_transaction;
}
return null;
} | Returns the currently active transaction.
@return CDbTransaction the currently active transaction. Null if no active transaction. | getCurrentTransaction | php | yiisoft/yii | framework/db/CDbConnection.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbConnection.php | BSD-3-Clause |
public function getSchema()
{
if($this->_schema!==null)
return $this->_schema;
else
{
$driver=$this->getDriverName();
if(isset($this->driverMap[$driver]))
return $this->_schema=Yii::createComponent($this->driverMap[$driver], $this);
else
throw new CDbException(Yii::t('yii','CDbConnection does not support reading schema for {driver} database.',
array('{driver}'=>$driver)));
}
} | Returns the database schema for the current connection
@throws CDbException if CDbConnection does not support reading schema for specified database driver
@return CDbSchema the database schema for the current connection | getSchema | php | yiisoft/yii | framework/db/CDbConnection.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbConnection.php | BSD-3-Clause |
public function getCommandBuilder()
{
return $this->getSchema()->getCommandBuilder();
} | Returns the SQL command builder for the current DB connection.
@return CDbCommandBuilder the command builder | getCommandBuilder | php | yiisoft/yii | framework/db/CDbConnection.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbConnection.php | BSD-3-Clause |
public function getLastInsertID($sequenceName='')
{
$this->setActive(true);
return $this->_pdo->lastInsertId($sequenceName);
} | Returns the ID of the last inserted row or sequence value.
@param string $sequenceName name of the sequence object (required by some DBMS)
@return string the row ID of the last row inserted, or the last value retrieved from the sequence object
@see https://www.php.net/manual/en/function.PDO-lastInsertId.php | getLastInsertID | php | yiisoft/yii | framework/db/CDbConnection.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbConnection.php | BSD-3-Clause |
public function quoteValue($str)
{
if(is_int($str) || is_float($str))
return $str;
$this->setActive(true);
return $this->quoteValueInternal($str, PDO::PARAM_STR);
} | Quotes a string value for use in a query.
@param string $str string to be quoted
@return string the properly quoted string
@see https://www.php.net/manual/en/function.PDO-quote.php | quoteValue | php | yiisoft/yii | framework/db/CDbConnection.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbConnection.php | BSD-3-Clause |
public function quoteValueWithType($value, $type)
{
$this->setActive(true);
return $this->quoteValueInternal($value, $type);
} | Quotes a value for use in a query using a given type.
@param mixed $value the value to be quoted.
@param integer $type The type to be used for quoting.
This should be one of the `PDO::PARAM_*` constants described in
{@link https://www.php.net/manual/en/pdo.constants.php PDO documentation}.
This parameter will be passed to the `PDO::quote()` function.
@return string the properly quoted string.
@see https://www.php.net/manual/en/function.PDO-quote.php
@since 1.1.18 | quoteValueWithType | php | yiisoft/yii | framework/db/CDbConnection.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbConnection.php | BSD-3-Clause |
private function quoteValueInternal($value, $type)
{
if(mb_stripos($this->connectionString, 'odbc:')===false)
{
if(($quoted=$this->_pdo->quote($value, $type))!==false)
return $quoted;
}
// fallback for drivers that don't support quote (e.g. oci and odbc)
return "'" . addcslashes(str_replace("'", "''", $value), "\000\n\r\\\032") . "'";
} | Quotes a value for use in a query using a given type. This method is internally used.
@param mixed $value
@param int $type
@return string | quoteValueInternal | php | yiisoft/yii | framework/db/CDbConnection.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbConnection.php | BSD-3-Clause |
public function quoteTableName($name)
{
return $this->getSchema()->quoteTableName($name);
} | Quotes a table name for use in a query.
If the table name contains schema prefix, the prefix will also be properly quoted.
@param string $name table name
@return string the properly quoted table name | quoteTableName | php | yiisoft/yii | framework/db/CDbConnection.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbConnection.php | BSD-3-Clause |
public function quoteColumnName($name)
{
return $this->getSchema()->quoteColumnName($name);
} | Quotes a column name for use in a query.
If the column name contains prefix, the prefix will also be properly quoted.
@param string $name column name
@return string the properly quoted column name | quoteColumnName | php | yiisoft/yii | framework/db/CDbConnection.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbConnection.php | BSD-3-Clause |
public function getPdoType($type)
{
static $map=array
(
'boolean'=>PDO::PARAM_BOOL,
'integer'=>PDO::PARAM_INT,
'string'=>PDO::PARAM_STR,
'resource'=>PDO::PARAM_LOB,
'NULL'=>PDO::PARAM_NULL,
);
return isset($map[$type]) ? $map[$type] : PDO::PARAM_STR;
} | Determines the PDO type for the specified PHP type.
@param string $type The PHP type (obtained by gettype() call).
@return integer the corresponding PDO type | getPdoType | php | yiisoft/yii | framework/db/CDbConnection.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbConnection.php | BSD-3-Clause |
public function getColumnCase()
{
return $this->getAttribute(PDO::ATTR_CASE);
} | Returns the case of the column names
@return mixed the case of the column names
@see https://www.php.net/manual/en/pdo.setattribute.php | getColumnCase | php | yiisoft/yii | framework/db/CDbConnection.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbConnection.php | BSD-3-Clause |
public function setColumnCase($value)
{
$this->setAttribute(PDO::ATTR_CASE,$value);
} | Sets the case of the column names.
@param mixed $value the case of the column names
@see https://www.php.net/manual/en/pdo.setattribute.php | setColumnCase | php | yiisoft/yii | framework/db/CDbConnection.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbConnection.php | BSD-3-Clause |
public function getNullConversion()
{
return $this->getAttribute(PDO::ATTR_ORACLE_NULLS);
} | Returns how the null and empty strings are converted.
@return mixed how the null and empty strings are converted
@see https://www.php.net/manual/en/pdo.setattribute.php | getNullConversion | php | yiisoft/yii | framework/db/CDbConnection.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbConnection.php | BSD-3-Clause |
public function setNullConversion($value)
{
$this->setAttribute(PDO::ATTR_ORACLE_NULLS,$value);
} | Sets how the null and empty strings are converted.
@param mixed $value how the null and empty strings are converted
@see https://www.php.net/manual/en/pdo.setattribute.php | setNullConversion | php | yiisoft/yii | framework/db/CDbConnection.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbConnection.php | BSD-3-Clause |
public function getAutoCommit()
{
return $this->getAttribute(PDO::ATTR_AUTOCOMMIT);
} | Returns whether creating or updating a DB record will be automatically committed.
Some DBMS (such as sqlite) may not support this feature.
@return boolean whether creating or updating a DB record will be automatically committed. | getAutoCommit | php | yiisoft/yii | framework/db/CDbConnection.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbConnection.php | BSD-3-Clause |
public function setAutoCommit($value)
{
$this->setAttribute(PDO::ATTR_AUTOCOMMIT,$value);
} | Sets whether creating or updating a DB record will be automatically committed.
Some DBMS (such as sqlite) may not support this feature.
@param boolean $value whether creating or updating a DB record will be automatically committed. | setAutoCommit | php | yiisoft/yii | framework/db/CDbConnection.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbConnection.php | BSD-3-Clause |
public function getPersistent()
{
return $this->getAttribute(PDO::ATTR_PERSISTENT);
} | Returns whether the connection is persistent or not.
Some DBMS (such as sqlite) may not support this feature.
@return boolean whether the connection is persistent or not | getPersistent | php | yiisoft/yii | framework/db/CDbConnection.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbConnection.php | BSD-3-Clause |
public function setPersistent($value)
{
return $this->setAttribute(PDO::ATTR_PERSISTENT,$value);
} | Sets whether the connection is persistent or not.
Some DBMS (such as sqlite) may not support this feature.
@param boolean $value whether the connection is persistent or not | setPersistent | php | yiisoft/yii | framework/db/CDbConnection.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbConnection.php | BSD-3-Clause |
public function getDriverName()
{
if($this->_driverName!==null)
return $this->_driverName;
elseif(($pos=strpos($this->connectionString,':'))!==false)
return $this->_driverName=strtolower(substr($this->connectionString,0,$pos));
//return $this->getAttribute(PDO::ATTR_DRIVER_NAME);
} | Returns the name of the DB driver.
@return string name of the DB driver. | getDriverName | php | yiisoft/yii | framework/db/CDbConnection.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbConnection.php | BSD-3-Clause |
public function setDriverName($driverName)
{
$this->_driverName=strtolower($driverName);
} | Changes the name of the DB driver. Overrides value extracted from the {@link connectionString},
which is behavior by default.
@param string $driverName to be set. Valid values are the keys from the {@link driverMap} property.
@see getDriverName
@see driverName
@since 1.1.16 | setDriverName | php | yiisoft/yii | framework/db/CDbConnection.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbConnection.php | BSD-3-Clause |
public function getClientVersion()
{
return $this->getAttribute(PDO::ATTR_CLIENT_VERSION);
} | Returns the version information of the DB driver.
@return string the version information of the DB driver | getClientVersion | php | yiisoft/yii | framework/db/CDbConnection.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbConnection.php | BSD-3-Clause |
public function getConnectionStatus()
{
return $this->getAttribute(PDO::ATTR_CONNECTION_STATUS);
} | Returns the status of the connection.
Some DBMS (such as sqlite) may not support this feature.
@return string the status of the connection | getConnectionStatus | php | yiisoft/yii | framework/db/CDbConnection.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbConnection.php | BSD-3-Clause |
public function getPrefetch()
{
return $this->getAttribute(PDO::ATTR_PREFETCH);
} | Returns whether the connection performs data prefetching.
@return boolean whether the connection performs data prefetching | getPrefetch | php | yiisoft/yii | framework/db/CDbConnection.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbConnection.php | BSD-3-Clause |
public function getServerInfo()
{
return $this->getAttribute(PDO::ATTR_SERVER_INFO);
} | Returns the information of DBMS server.
@return string the information of DBMS server | getServerInfo | php | yiisoft/yii | framework/db/CDbConnection.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbConnection.php | BSD-3-Clause |
public function getServerVersion()
{
return $this->getAttribute(PDO::ATTR_SERVER_VERSION);
} | Returns the version information of DBMS server.
@return string the version information of DBMS server | getServerVersion | php | yiisoft/yii | framework/db/CDbConnection.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbConnection.php | BSD-3-Clause |
public function getTimeout()
{
return $this->getAttribute(PDO::ATTR_TIMEOUT);
} | Returns the timeout settings for the connection.
@return integer timeout settings for the connection | getTimeout | php | yiisoft/yii | framework/db/CDbConnection.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbConnection.php | BSD-3-Clause |
public function getAttribute($name)
{
$this->setActive(true);
return $this->_pdo->getAttribute($name);
} | Obtains a specific DB connection attribute information.
@param integer $name the attribute to be queried
@return mixed the corresponding attribute information
@see https://www.php.net/manual/en/function.PDO-getAttribute.php | getAttribute | php | yiisoft/yii | framework/db/CDbConnection.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbConnection.php | BSD-3-Clause |
public function setAttribute($name,$value)
{
if($this->_pdo instanceof PDO)
$this->_pdo->setAttribute($name,$value);
else
$this->_attributes[$name]=$value;
} | Sets an attribute on the database connection.
@param integer $name the attribute to be set
@param mixed $value the attribute value
@see https://www.php.net/manual/en/function.PDO-setAttribute.php | setAttribute | php | yiisoft/yii | framework/db/CDbConnection.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbConnection.php | BSD-3-Clause |
public function getAttributes()
{
return $this->_attributes;
} | Returns the attributes that are previously explicitly set for the DB connection.
@return array attributes (name=>value) that are previously explicitly set for the DB connection.
@see setAttributes
@since 1.1.7 | getAttributes | php | yiisoft/yii | framework/db/CDbConnection.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbConnection.php | BSD-3-Clause |
public function setAttributes($values)
{
foreach($values as $name=>$value)
$this->_attributes[$name]=$value;
} | Sets a set of attributes on the database connection.
@param array $values attributes (name=>value) to be set.
@see setAttribute
@since 1.1.7 | setAttributes | php | yiisoft/yii | framework/db/CDbConnection.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbConnection.php | BSD-3-Clause |
public function getStats()
{
$logger=Yii::getLogger();
$timings=$logger->getProfilingResults(null,'system.db.CDbCommand.query');
$count=count($timings);
$time=array_sum($timings);
$timings=$logger->getProfilingResults(null,'system.db.CDbCommand.execute');
$count+=count($timings);
$time+=array_sum($timings);
return array($count,$time);
} | Returns the statistical results of SQL executions.
The results returned include the number of SQL statements executed and
the total time spent.
In order to use this method, {@link enableProfiling} has to be set true.
@return array the first element indicates the number of SQL statements executed,
and the second element the total time spent in SQL execution. | getStats | php | yiisoft/yii | framework/db/CDbConnection.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbConnection.php | BSD-3-Clause |
public function getColumn($name)
{
return isset($this->columns[$name]) ? $this->columns[$name] : null;
} | Gets the named column metadata.
This is a convenient method for retrieving a named column even if it does not exist.
@param string $name column name
@return CDbColumnSchema metadata of the named column. Null if the named column does not exist. | getColumn | php | yiisoft/yii | framework/db/schema/CDbTableSchema.php | https://github.com/yiisoft/yii/blob/master/framework/db/schema/CDbTableSchema.php | BSD-3-Clause |
public function getTable($name,$refresh=false)
{
if($refresh===false && isset($this->_tables[$name]))
return $this->_tables[$name];
else
{
if($this->_connection->tablePrefix!==null && strpos($name,'{{')!==false)
$realName=preg_replace('/\{\{(.*?)\}\}/',$this->_connection->tablePrefix.'$1',$name);
else
$realName=$name;
// temporarily disable query caching
if($this->_connection->queryCachingDuration>0)
{
$qcDuration=$this->_connection->queryCachingDuration;
$this->_connection->queryCachingDuration=0;
}
if(!isset($this->_cacheExclude[$name]) && ($duration=$this->_connection->schemaCachingDuration)>0 && $this->_connection->schemaCacheID!==false && ($cache=Yii::app()->getComponent($this->_connection->schemaCacheID))!==null)
{
$key='yii:dbschema'.$this->_connection->connectionString.':'.$this->_connection->username.':'.$name;
$table=$cache->get($key);
if($refresh===true || $table===false)
{
$table=$this->loadTable($realName);
if($table!==null)
$cache->set($key,$table,$duration);
}
$this->_tables[$name]=$table;
}
else
$this->_tables[$name]=$table=$this->loadTable($realName);
if(isset($qcDuration)) // re-enable query caching
$this->_connection->queryCachingDuration=$qcDuration;
return $table;
}
} | Obtains the metadata for the named table.
@param string $name table name
@param boolean $refresh if we need to refresh schema cache for a table.
Parameter available since 1.1.9
@return CDbTableSchema table metadata. Null if the named table does not exist. | getTable | php | yiisoft/yii | framework/db/schema/CDbSchema.php | https://github.com/yiisoft/yii/blob/master/framework/db/schema/CDbSchema.php | BSD-3-Clause |
public function getTables($schema='')
{
$tables=array();
foreach($this->getTableNames($schema) as $name)
{
if(($table=$this->getTable($name))!==null)
$tables[$name]=$table;
}
return $tables;
} | Returns the metadata for all tables in the database.
@param string $schema the schema of the tables. Defaults to empty string, meaning the current or default schema.
@return array the metadata for all tables in the database.
Each array element is an instance of {@link CDbTableSchema} (or its child class).
The array keys are table names. | getTables | php | yiisoft/yii | framework/db/schema/CDbSchema.php | https://github.com/yiisoft/yii/blob/master/framework/db/schema/CDbSchema.php | BSD-3-Clause |
public function getTableNames($schema='')
{
if(!isset($this->_tableNames[$schema]))
$this->_tableNames[$schema]=$this->findTableNames($schema);
return $this->_tableNames[$schema];
} | Returns all table names in the database.
@param string $schema the schema of the tables. Defaults to empty string, meaning the current or default schema.
If not empty, the returned table names will be prefixed with the schema name.
@return array all table names in the database. | getTableNames | php | yiisoft/yii | framework/db/schema/CDbSchema.php | https://github.com/yiisoft/yii/blob/master/framework/db/schema/CDbSchema.php | BSD-3-Clause |
public function refresh()
{
if(($duration=$this->_connection->schemaCachingDuration)>0 && $this->_connection->schemaCacheID!==false && ($cache=Yii::app()->getComponent($this->_connection->schemaCacheID))!==null)
{
foreach(array_keys($this->_tables) as $name)
{
if(!isset($this->_cacheExclude[$name]))
{
$key='yii:dbschema'.$this->_connection->connectionString.':'.$this->_connection->username.':'.$name;
$cache->delete($key);
}
}
}
$this->_tables=array();
$this->_tableNames=array();
$this->_builder=null;
} | Refreshes the schema.
This method resets the loaded table metadata and command builder
so that they can be recreated to reflect the change of schema. | refresh | php | yiisoft/yii | framework/db/schema/CDbSchema.php | https://github.com/yiisoft/yii/blob/master/framework/db/schema/CDbSchema.php | BSD-3-Clause |
public function quoteTableName($name)
{
if(strpos($name,'.')===false)
return $this->quoteSimpleTableName($name);
$parts=explode('.',$name);
foreach($parts as $i=>$part)
$parts[$i]=$this->quoteSimpleTableName($part);
return implode('.',$parts);
} | Quotes a table name for use in a query.
If the table name contains schema prefix, the prefix will also be properly quoted.
@param string $name table name
@return string the properly quoted table name
@see quoteSimpleTableName | quoteTableName | php | yiisoft/yii | framework/db/schema/CDbSchema.php | https://github.com/yiisoft/yii/blob/master/framework/db/schema/CDbSchema.php | BSD-3-Clause |
public function quoteSimpleTableName($name)
{
return "'".$name."'";
} | Quotes a simple table name for use in a query.
A simple table name does not schema prefix.
@param string $name table name
@return string the properly quoted table name
@since 1.1.6 | quoteSimpleTableName | php | yiisoft/yii | framework/db/schema/CDbSchema.php | https://github.com/yiisoft/yii/blob/master/framework/db/schema/CDbSchema.php | BSD-3-Clause |
public function quoteSimpleColumnName($name)
{
return '"'.$name.'"';
} | Quotes a simple column name for use in a query.
A simple column name does not contain prefix.
@param string $name column name
@return string the properly quoted column name
@since 1.1.6 | quoteSimpleColumnName | php | yiisoft/yii | framework/db/schema/CDbSchema.php | https://github.com/yiisoft/yii/blob/master/framework/db/schema/CDbSchema.php | BSD-3-Clause |
public function compareTableNames($name1,$name2)
{
$name1=str_replace(array('"','`',"'"),'',$name1);
$name2=str_replace(array('"','`',"'"),'',$name2);
if(($pos=strrpos($name1,'.'))!==false)
$name1=substr($name1,$pos+1);
if(($pos=strrpos($name2,'.'))!==false)
$name2=substr($name2,$pos+1);
if($this->_connection->tablePrefix!==null)
{
if(strpos($name1,'{')!==false)
$name1=$this->_connection->tablePrefix.str_replace(array('{','}'),'',$name1);
if(strpos($name2,'{')!==false)
$name2=$this->_connection->tablePrefix.str_replace(array('{','}'),'',$name2);
}
return $name1===$name2;
} | Compares two table names.
The table names can be either quoted or unquoted. This method
will consider both cases.
@param string $name1 table name 1
@param string $name2 table name 2
@return boolean whether the two table names refer to the same table. | compareTableNames | php | yiisoft/yii | framework/db/schema/CDbSchema.php | https://github.com/yiisoft/yii/blob/master/framework/db/schema/CDbSchema.php | BSD-3-Clause |
public function resetSequence($table,$value=null)
{
} | Resets the sequence value of a table's primary key.
The sequence will be reset such that the primary key of the next new row inserted
will have the specified value or max value of a primary key plus one (i.e. sequence trimming).
@param CDbTableSchema $table the table schema whose primary key sequence will be reset
@param integer|null $value the value for the primary key of the next new row inserted.
If this is not set, the next new row's primary key will have the max value of a primary
key plus one (i.e. sequence trimming).
@since 1.1 | resetSequence | php | yiisoft/yii | framework/db/schema/CDbSchema.php | https://github.com/yiisoft/yii/blob/master/framework/db/schema/CDbSchema.php | BSD-3-Clause |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.