![]() Such as attributes, validation rules, data serialization, etc. ![]() For this reason, we usually put Active RecordĬlasses under the app\models namespace (or other namespaces for keeping model classes).īecause yii\db\ActiveRecord extends from yii\base\Model, it inherits all model features, * string the name of the table associated with this ActiveRecord class.Īctive Record instances are considered as models. In the following example, we declare an Active Record class named Customer for the customer database table. The brackets around the table name are used for TablePrefix is tbl_, Customer becomes tbl_customer and OrderItem becomes tbl_order_item. You may override this method if the table is not named after this convention.Īlso a default tablePrefix can be applied. The tableName() method returns the table name by converting the class name via yii\helpers\Inflector::camel2id(). Setting a table name ¶īy default each Active Record class is associated with its database table. To get started, declare an Active Record class by extending yii\db\ActiveRecord. However, most content described here are also applicable to Active Record for NoSQL databases. In this tutorial, we will mainly describe the usage of Active Record for relational databases. MongoDB 1.3.0 or later: via yii\mongodb\ActiveRecord, requires the yii2-mongodb extension. ![]() Redis 2.6.12 or later: via yii\redis\ActiveRecord, requires the yii2-redis extension.ElasticSearch: via yii\elasticsearch\ActiveRecord, requires the yii2-elasticsearch extensionĪdditionally, Yii also supports using Active Record with the following NoSQL databases:.Sphinx: via yii\sphinx\ActiveRecord, requires the yii2-sphinx extension.The cubrid PDO extension, quoting of values will not work, so you need CUBRID 9.3 as the client as well as the server) CUBRID 9.3 or later: via yii\db\ActiveRecord (Note that due to a bug in.Microsoft SQL Server 2008 or later: via yii\db\ActiveRecord.SQLite 2 and 3: via yii\db\ActiveRecord.PostgreSQL 7.3 or later: via yii\db\ActiveRecord.MySQL 4.1 or later: via yii\db\ActiveRecord.Yii provides the Active Record support for the following relational databases: Intuitive, more error prone, and may even have compatibility problems if you are using a different kind of database: $db->createCommand( 'INSERT INTO `customer` (`name`) VALUES (:name)', [ The above code is equivalent to using the following raw SQL statement for MySQL, which is less Row into the customer table: $customer = new Customer() You can write the following code to insert a new ![]() You would access Active Record attributes and call Active Record methods to access and manipulate the data storedįor example, assume Customer is an Active Record class which is associated with the customer tableĪnd name is a column of the customer table. Instance represents the value of a particular column in that row. An Active Record class is associated with a database table,Īn Active Record instance corresponds to a row of that table, and an attribute of an Active Record Active Record provides an object-oriented interfaceįor accessing and manipulating data stored in databases.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |