* $connection=new CDbConnection($dsn,$username,$password); * $connection->active=true; *
* $command=$connection->createCommand($sqlStatement); * $command->execute(); // a non-query SQL statement execution * // or execute an SQL query and fetch the result set * $reader=$command->query(); * * // each $row is an array representing a row of data * foreach($reader as $row) ... *
* $command=$connection->createCommand($sqlStatement); * $command->bindParam($name1,$value1); * $command->bindParam($name2,$value2); * $command->execute(); *
* $transaction=$connection->beginTransaction(); * try * { * $connection->createCommand($sql1)->execute(); * $connection->createCommand($sql2)->execute(); * //.... other SQL executions * $transaction->commit(); * } * catch(Exception $e) * { * $transaction->rollback(); * } *
* array( * 'components'=>array( * 'db'=>array( * 'class'=>'CDbConnection', * 'connectionString'=>'sqlite:path/to/dbfile', * ), * ), * ) *
* 'db'=>array( * 'class'=>'CDbConnection', * 'driverName'=>'mysql', * 'connectionString'=>'odbc:Driver={MySQL};Server=127.0.0.1;Database=test', * 'username'=>'', * 'password'=>'', * ), *