From 271aecb01606148fa47d41586b401e2f5bb32386 Mon Sep 17 00:00:00 2001 From: Carsten Brandt Date: Wed, 3 Jul 2013 02:04:46 +0200 Subject: [PATCH] Update database-basics.md --- docs/guide/database-basics.md | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/docs/guide/database-basics.md b/docs/guide/database-basics.md index b98b057..ee003b6 100644 --- a/docs/guide/database-basics.md +++ b/docs/guide/database-basics.md @@ -5,6 +5,7 @@ Yii has a database access layer built on top of PHP's [PDO](http://www.php.net/m uniform API and solves some inconsistencies between different DBMS. By default Yii supports MySQL, SQLite, PostgreSQL, Oracle and MSSQL. + Configuration ------------- @@ -28,21 +29,21 @@ return array( ); ``` -After component is configured you can access using the following syntax: +After the component is configured you can access it using the following syntax: ```php $connection = \Yii::$app->db; ``` You can refer to [[\yii\db\Connection]] for a list of properties you can configure. Also note that you can define more -than one connection components and use both at the same time if needed: +than one connection component and use both at the same time if needed: ```php $primaryConnection = \Yii::$app->db; $secondaryConnection = \Yii::$app->secondDb; ``` -If you don't want to define connection as application component you can instantiate it directly: +If you don't want to define the connection as an application component you can instantiate it directly: ```php $connection = new \yii\db\Connection(array( @@ -53,6 +54,7 @@ $connection = new \yii\db\Connection(array( $connection->open(); ``` + Basic SQL queries ----------------- @@ -70,7 +72,7 @@ $posts = $command->queryAll(); When only a single row is returned: ```php -$command = $connection->createCommand('SELECT * FROM tbl_post LIMIT 1'); +$command = $connection->createCommand('SELECT * FROM tbl_post WHERE id=1'); $post = $command->query(); ``` @@ -93,7 +95,7 @@ $postCount = $command->queryScalar(); If SQL executed doesn't return any data you can use command's `execute` method: ```php -$command = $connection->createCommand('UPDATE tbl_post SET status=1'); +$command = $connection->createCommand('UPDATE tbl_post SET status=1 WHERE id=1'); $command->execute(); ``` @@ -196,7 +198,7 @@ Aside from basic SQL queries [[\yii\db\Command]] contains a set of methods allow These can be used as follows: ```php -// UPDATE +// CREATE TABLE $connection->createCommand()->createTable('tbl_post', array( 'id' => 'pk', 'title' => 'string',