code
stringlengths 17
247k
| 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 createTable($table, $columns, $options=null)
{
echo " > create table $table ...";
$time=microtime(true);
$this->getDbConnection()->createCommand()->createTable($table, $columns, $options);
echo " done (time: ".sprintf('%.3f', microtime(true)-$time)."s)\n";
} | 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. | createTable | php | yiisoft/yii | framework/db/CDbMigration.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbMigration.php | BSD-3-Clause |
public function renameTable($table, $newName)
{
echo " > rename table $table to $newName ...";
$time=microtime(true);
$this->getDbConnection()->createCommand()->renameTable($table, $newName);
echo " done (time: ".sprintf('%.3f', microtime(true)-$time)."s)\n";
} | 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. | renameTable | php | yiisoft/yii | framework/db/CDbMigration.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbMigration.php | BSD-3-Clause |
public function dropTable($table)
{
echo " > drop table $table ...";
$time=microtime(true);
$this->getDbConnection()->createCommand()->dropTable($table);
echo " done (time: ".sprintf('%.3f', microtime(true)-$time)."s)\n";
} | 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. | dropTable | php | yiisoft/yii | framework/db/CDbMigration.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbMigration.php | BSD-3-Clause |
public function truncateTable($table)
{
echo " > truncate table $table ...";
$time=microtime(true);
$this->getDbConnection()->createCommand()->truncateTable($table);
echo " done (time: ".sprintf('%.3f', microtime(true)-$time)."s)\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. | truncateTable | php | yiisoft/yii | framework/db/CDbMigration.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbMigration.php | BSD-3-Clause |
public function addColumn($table, $column, $type)
{
echo " > add column $column $type to table $table ...";
$time=microtime(true);
$this->getDbConnection()->createCommand()->addColumn($table, $column, $type);
echo " done (time: ".sprintf('%.3f', microtime(true)-$time)."s)\n";
} | 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'. | addColumn | php | yiisoft/yii | framework/db/CDbMigration.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbMigration.php | BSD-3-Clause |
public function dropColumn($table, $column)
{
echo " > drop column $column from table $table ...";
$time=microtime(true);
$this->getDbConnection()->createCommand()->dropColumn($table, $column);
echo " done (time: ".sprintf('%.3f', microtime(true)-$time)."s)\n";
} | 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. | dropColumn | php | yiisoft/yii | framework/db/CDbMigration.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbMigration.php | BSD-3-Clause |
public function renameColumn($table, $name, $newName)
{
echo " > rename column $name in table $table to $newName ...";
$time=microtime(true);
$this->getDbConnection()->createCommand()->renameColumn($table, $name, $newName);
echo " done (time: ".sprintf('%.3f', microtime(true)-$time)."s)\n";
} | 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. | renameColumn | php | yiisoft/yii | framework/db/CDbMigration.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbMigration.php | BSD-3-Clause |
public function alterColumn($table, $column, $type)
{
echo " > alter column $column in table $table to $type ...";
$time=microtime(true);
$this->getDbConnection()->createCommand()->alterColumn($table, $column, $type);
echo " done (time: ".sprintf('%.3f', microtime(true)-$time)."s)\n";
} | 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'. | alterColumn | php | yiisoft/yii | framework/db/CDbMigration.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbMigration.php | BSD-3-Clause |
public function dropForeignKey($name, $table)
{
echo " > drop foreign key $name from table $table ...";
$time=microtime(true);
$this->getDbConnection()->createCommand()->dropForeignKey($name, $table);
echo " done (time: ".sprintf('%.3f', microtime(true)-$time)."s)\n";
} | 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. | dropForeignKey | php | yiisoft/yii | framework/db/CDbMigration.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbMigration.php | BSD-3-Clause |
public function dropIndex($name, $table)
{
echo " > drop index $name ...";
$time=microtime(true);
$this->getDbConnection()->createCommand()->dropIndex($name, $table);
echo " done (time: ".sprintf('%.3f', microtime(true)-$time)."s)\n";
} | 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. | dropIndex | php | yiisoft/yii | framework/db/CDbMigration.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbMigration.php | BSD-3-Clause |
public function refreshTableSchema($table)
{
echo " > refresh table $table schema cache ...";
$time=microtime(true);
$this->getDbConnection()->getSchema()->getTable($table,true);
echo " done (time: ".sprintf('%.3f', microtime(true)-$time)."s)\n";
} | Refreshed schema cache for a table
@param string $table name of the table to refresh
@since 1.1.9 | refreshTableSchema | php | yiisoft/yii | framework/db/CDbMigration.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbMigration.php | BSD-3-Clause |
public function dropPrimaryKey($name,$table)
{
echo " > alter table $table drop primary key $name ...";
$time=microtime(true);
$this->getDbConnection()->createCommand()->dropPrimaryKey($name,$table);
echo " done (time: ".sprintf('%.3f', microtime(true)-$time)."s)\n";
} | Builds and executes a SQL statement for removing a primary key, supports composite primary keys.
@param string $name name of the constraint to remove
@param string $table name of the table to remove primary key from
@since 1.1.13 | dropPrimaryKey | php | yiisoft/yii | framework/db/CDbMigration.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbMigration.php | BSD-3-Clause |
public function bindColumn($column, &$value, $dataType=null)
{
if($dataType===null)
$this->_statement->bindColumn($column,$value);
else
$this->_statement->bindColumn($column,$value,$dataType);
} | Binds a column to a PHP variable.
When rows of data are being fetched, the corresponding column value
will be set in the variable. Note, the fetch mode must include PDO::FETCH_BOUND.
@param mixed $column Number of the column (1-indexed) or name of the column
in the result set. If using the column name, be aware that the name
should match the case of the column, as returned by the driver.
@param mixed $value Name of the PHP variable to which the column will be bound.
@param integer $dataType Data type of the parameter
@see https://www.php.net/manual/en/function.PDOStatement-bindColumn.php | bindColumn | php | yiisoft/yii | framework/db/CDbDataReader.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbDataReader.php | BSD-3-Clause |
public function setFetchMode($mode)
{
$params=func_get_args();
call_user_func_array(array($this->_statement,'setFetchMode'),$params);
} | Set the default fetch mode for this statement
@param mixed $mode fetch mode
@see https://www.php.net/manual/en/function.PDOStatement-setFetchMode.php | setFetchMode | php | yiisoft/yii | framework/db/CDbDataReader.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbDataReader.php | BSD-3-Clause |
public function read()
{
return $this->_statement->fetch();
} | Advances the reader to the next row in a result set.
@return array|false the current row, false if no more row available | read | php | yiisoft/yii | framework/db/CDbDataReader.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbDataReader.php | BSD-3-Clause |
public function readColumn($columnIndex)
{
return $this->_statement->fetchColumn($columnIndex);
} | Returns a single column from the next row of a result set.
@param integer $columnIndex zero-based column index
@return mixed|false the column of the current row, false if no more row available | readColumn | php | yiisoft/yii | framework/db/CDbDataReader.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbDataReader.php | BSD-3-Clause |
public function readObject($className,$fields)
{
return $this->_statement->fetchObject($className,$fields);
} | Returns an object populated with the next row of data.
@param string $className class name of the object to be created and populated
@param array $fields Elements of this array are passed to the constructor
@return mixed|false the populated object, false if no more row of data available | readObject | php | yiisoft/yii | framework/db/CDbDataReader.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbDataReader.php | BSD-3-Clause |
public function readAll()
{
return $this->_statement->fetchAll();
} | Reads the whole result set into an array.
@return array the result set (each array element represents a row of data).
An empty array will be returned if the result contains no row. | readAll | php | yiisoft/yii | framework/db/CDbDataReader.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbDataReader.php | BSD-3-Clause |
public function nextResult()
{
if(($result=$this->_statement->nextRowset())!==false)
$this->_index=-1;
return $result;
} | Advances the reader to the next result when reading the results of a batch of statements.
This method is only useful when there are multiple result sets
returned by the query. Not all DBMS support this feature.
@return boolean Returns true on success or false on failure. | nextResult | php | yiisoft/yii | framework/db/CDbDataReader.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbDataReader.php | BSD-3-Clause |
public function close()
{
$this->_statement->closeCursor();
$this->_closed=true;
} | Closes the reader.
This frees up the resources allocated for executing this SQL statement.
Read attempts after this method call are unpredictable. | close | php | yiisoft/yii | framework/db/CDbDataReader.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbDataReader.php | BSD-3-Clause |
public function getIsClosed()
{
return $this->_closed;
} | whether the reader is closed or not.
@return boolean whether the reader is closed or not. | getIsClosed | php | yiisoft/yii | framework/db/CDbDataReader.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbDataReader.php | BSD-3-Clause |
public function getRowCount()
{
return $this->_statement->rowCount();
} | Returns the number of rows in the result set.
Note, most DBMS may not give a meaningful count.
In this case, use "SELECT COUNT(*) FROM tableName" to obtain the number of rows.
@return integer number of rows contained in the result. | getRowCount | php | yiisoft/yii | framework/db/CDbDataReader.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbDataReader.php | BSD-3-Clause |
public function count()
{
return $this->getRowCount();
} | Returns the number of rows in the result set.
This method is required by the Countable interface.
Note, most DBMS may not give a meaningful count.
In this case, use "SELECT COUNT(*) FROM tableName" to obtain the number of rows.
@return integer number of rows contained in the result. | count | php | yiisoft/yii | framework/db/CDbDataReader.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbDataReader.php | BSD-3-Clause |
public function getColumnCount()
{
return $this->_statement->columnCount();
} | Returns the number of columns in the result set.
Note, even there's no row in the reader, this still gives correct column number.
@return integer the number of columns in the result set. | getColumnCount | php | yiisoft/yii | framework/db/CDbDataReader.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbDataReader.php | BSD-3-Clause |
public function rewind()
{
if($this->_index<0)
{
$this->_row=$this->_statement->fetch();
$this->_index=0;
}
else
throw new CDbException(Yii::t('yii','CDbDataReader cannot rewind. It is a forward-only reader.'));
} | Resets the iterator to the initial state.
This method is required by the interface Iterator.
@throws CException if this method is invoked twice | rewind | php | yiisoft/yii | framework/db/CDbDataReader.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbDataReader.php | BSD-3-Clause |
public function key()
{
return $this->_index;
} | Returns the index of the current row.
This method is required by the interface Iterator.
@return integer the index of the current row. | key | php | yiisoft/yii | framework/db/CDbDataReader.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbDataReader.php | BSD-3-Clause |
public function current()
{
return $this->_row;
} | Returns the current row.
This method is required by the interface Iterator.
@return mixed the current row. | current | php | yiisoft/yii | framework/db/CDbDataReader.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbDataReader.php | BSD-3-Clause |
public function next()
{
$this->_row=$this->_statement->fetch();
$this->_index++;
} | Moves the internal pointer to the next row.
This method is required by the interface Iterator. | next | php | yiisoft/yii | framework/db/CDbDataReader.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbDataReader.php | BSD-3-Clause |
public function valid()
{
return $this->_row!==false;
} | Returns whether there is a row of data at current position.
This method is required by the interface Iterator.
@return boolean whether there is a row of data at current position. | valid | php | yiisoft/yii | framework/db/CDbDataReader.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbDataReader.php | BSD-3-Clause |
public function __sleep()
{
$this->_statement=null;
return array_keys(get_object_vars($this));
} | Set the statement to null when serializing.
@return array | __sleep | php | yiisoft/yii | framework/db/CDbCommand.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbCommand.php | BSD-3-Clause |
public function setFetchMode($mode)
{
$params=func_get_args();
$this->_fetchMode = $params;
return $this;
} | Set the default fetch mode for this statement
@param mixed $mode fetch mode
@return static
@see https://www.php.net/manual/en/function.PDOStatement-setFetchMode.php
@since 1.1.7 | setFetchMode | php | yiisoft/yii | framework/db/CDbCommand.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbCommand.php | BSD-3-Clause |
public function reset()
{
$this->_text=null;
$this->_query=null;
$this->_statement=null;
$this->_paramLog=array();
$this->params=array();
return $this;
} | Cleans up the command and prepares for building a new query.
This method is mainly used when a command object is being reused
multiple times for building different queries.
Calling this method will clean up all internal states of the command object.
@return static this command instance
@since 1.1.6 | reset | php | yiisoft/yii | framework/db/CDbCommand.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbCommand.php | BSD-3-Clause |
public function setText($value)
{
if($this->_connection->tablePrefix!==null && $value!='')
$this->_text=preg_replace('/{{(.*?)}}/',$this->_connection->tablePrefix.'\1',$value);
else
$this->_text=$value;
$this->cancel();
return $this;
} | Specifies the SQL statement to be executed.
Any previous execution will be terminated or cancel.
@param string $value the SQL statement to be executed
@return static this command instance | setText | php | yiisoft/yii | framework/db/CDbCommand.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbCommand.php | BSD-3-Clause |
public function getPdoStatement()
{
return $this->_statement;
} | @return PDOStatement the underlying PDOStatement for this command
It could be null if the statement is not prepared yet. | getPdoStatement | php | yiisoft/yii | framework/db/CDbCommand.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbCommand.php | BSD-3-Clause |
public function prepare()
{
if($this->_statement==null)
{
try
{
$this->_statement=$this->getConnection()->getPdoInstance()->prepare($this->getText());
$this->_paramLog=array();
}
catch(Exception $e)
{
Yii::log('Error in preparing SQL: '.$this->getText(),CLogger::LEVEL_ERROR,'system.db.CDbCommand');
$errorInfo=$e instanceof PDOException ? $e->errorInfo : null;
throw new CDbException(Yii::t('yii','CDbCommand failed to prepare the SQL statement: {error}',
array('{error}'=>$e->getMessage())),(int)$e->getCode(),$errorInfo);
}
}
} | Prepares the SQL statement to be executed.
For complex SQL statement that is to be executed multiple times,
this may improve performance.
For SQL statement with binding parameters, this method is invoked
automatically.
@throws CDbException if CDbCommand failed to prepare the SQL statement | prepare | php | yiisoft/yii | framework/db/CDbCommand.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbCommand.php | BSD-3-Clause |
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 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.