


How to use Active Record mode in yii2, yii2record_PHP tutorial
How to use Active Record mode in yii2, yii2record
The example in this article describes the method of using Active Record mode in yii2. Share it with everyone for your reference, the details are as follows:
1. Configure the corresponding database information in db.php:
return [ 'class' => 'yii\db\Connection', 'dsn' => 'mysql:host=localhost;dbname=yii2basic', 'username' => 'root', 'password' => '', 'charset' => 'utf8', ];
2. Use the gii module to automatically generate the corresponding code (visit the link http://localhost/basic/web/index.php?r=gii):
Use ModelGenerator and CURD Generator to automatically generate corresponding model code and code for addition, deletion, modification and query
3. When the table in the database needs to be modified, you can use migration:
Execute the command in the project: ./yii migrate/create “define your own name”
A new folder migrations will be generated in the project, open the file in the folder:
class m150225_022640_modify_book_table extends Migration { public function up() { $this->addColumn("book", "book_desc", yii\db\mssql\Schema::TYPE_TEXT); } public function down() { echo "m150225_022640_modify_book_table cannot be reverted.\n"; return false; } }
Use the command in the command line: ./yii migrate to execute the up function in the script
Use the command in the command line: ./yii migrate/down to execute the down function in the script
I hope this article will be helpful to everyone’s PHP program design based on the Yii framework.
Articles you may be interested in:
- Yii2 uses Bootbox plug-in to implement custom pop-up windows
- Learn YII2 framework from scratch (4) Extension plug-in yii2-kartikgii
- Learn the YII2 framework from scratch (3) Extend the plug-in yii2-gird
- Learn the YII2 framework from scratch (2) Install the extension plug-in through Composer
- Use the drop-down menu in the yii2 framework Automatic search yii-widget-select2 instance analysis
- YII2.0 Activeform form component usage example
- Implementation method of adding verification code in yii2
- Yii2 framework reference bootstrap Methods of date plug-in yii2-date-picker

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

How to remove jquery from yii2: 1. Edit the AppAsset.php file and comment out the "yii\web\YiiAsset" value in the variable $depends; 2. Edit the main.php file and add the configuration "'yii" under the field "components" \web\JqueryAsset' => ['js' => [],'sourcePath' => null,]," to remove the jquery script.

With the continuous development of cloud computing technology, data backup has become something that every enterprise must do. In this context, it is particularly important to develop a highly available cloud backup system. The PHP framework Yii is a powerful framework that can help developers quickly build high-performance web applications. The following will introduce how to use the Yii framework to develop a highly available cloud backup system. Designing the database model In the Yii framework, the database model is a very important part. Because the data backup system requires a lot of tables and relationships

As the Internet continues to develop, the demand for web application development is also getting higher and higher. For developers, developing applications requires a stable, efficient, and powerful framework, which can improve development efficiency. Yii is a leading high-performance PHP framework that provides rich features and good performance. Yii3 is the next generation version of the Yii framework, which further optimizes performance and code quality based on Yii2. In this article, we will introduce how to use Yii3 framework to develop PHP applications.

In the current information age, big data, artificial intelligence, cloud computing and other technologies have become the focus of major enterprises. Among these technologies, graphics card rendering technology, as a high-performance graphics processing technology, has received more and more attention. Graphics card rendering technology is widely used in game development, film and television special effects, engineering modeling and other fields. For developers, choosing a framework that suits their projects is a very important decision. Among current languages, PHP is a very dynamic language. Some excellent PHP frameworks such as Yii2, Ph

As the demand for web applications continues to grow, developers have more and more choices in choosing development frameworks. Symfony and Yii2 are two popular PHP frameworks. They both have powerful functions and performance, but when faced with the need to develop large-scale web applications, which framework is more suitable? Next we will conduct a comparative analysis of Symphony and Yii2 to help you make a better choice. Basic Overview Symphony is an open source web application framework written in PHP and is built on

The Yii framework is an open source PHP Web application framework that provides numerous tools and components to simplify the process of Web application development, of which data query is one of the important components. In the Yii framework, we can use SQL-like syntax to access the database to query and manipulate data efficiently. The query builder of the Yii framework mainly includes the following types: ActiveRecord query, QueryBuilder query, command query and original SQL query

The hype for Black Myth: Wukong has been felt globally as the game slowly crawled towards its launch date, and it didn't disappoint when it launched on August 20, having received a very warm welcome from the gaming community at large. After being onl
