Phpyii framework web project connection database and crud _ PHP Tutorial

Source: Internet
Author: User
The phpyii framework web project connects to the database and performs crud operations. The previous article introduced how to configure the yii Framework. in this article, we will learn about the yii crud operation. If you do not know, you can leave a message for me. First, find the configuration file of our wen project. the previous article describes how to configure the yii Framework. then we will learn about the yii crud operation. If you do not know, you can leave a message for me.

First, find the configuration file of our wen project, which has three pages in .. \ yiiphp \ protected \ config to open its main. php

Page effects we saw at the beginning

Next, we will change the project title to "my php project". here, the main. php modified

Change the gray part of row 10 to "my php project", so that the title is successfully modified,

Next we will establish a database to connect to php. for example, I have created a mysql database named "yiitest" and a "user" table with two Fields. the following code is provided:

mysql> create database yiitest;Query OK, 1 row affected (0.00 sec)mysql> use yiitest;Database changedmysql> create table user(    -> id int primary key auto_increment,    -> name varchar(20) not null,    -> pwd varchar(20) not null);Query OK, 0 rows affected (0.06 sec)


In this way, our database has been built. we will continue to modify the configuration file of main. php and first provide the original configuration,

Comment out rows 50 to 52, then release rows 55 to 61, and change the 56 rows of dbname = "testdrive" to dbname = 'yiitest '. There are also lines 58 to 59 that you are looking at and changing, because my database has no password, so I ignore it, and now the modified:

In this way, our database connection is complete (the effect is not visible for the moment). then we continue to configure gii and draw a gourd based on the sample. we will provide the original configuration of main. php:

All we need to do is release 24 to 29 lines of code and change the 26 lines of "password" => 'Enter Your password' to what you want, for example, 'password' => 'password', modified configuration

In this way, the main. php file is basically configured. now we can check the effect and open the browser and enter: http: // localhost/yiiphp/index. php? R = gii. log on to the password you just set. <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHA + pgltzybzcm9 "http://www.2cto.com/uploadfile/Collfiles/20140214/20140214084303187.jpg" alt = "\">

Click the third hyperlink-Model Generator, which means to generate the Model program. click it and enter the user table of our database.

Click Generate to Generate the program class file. Next, click the second crud Generator hyperlink to use the generated class file named "User", click the Preview button, and then click Generate, in this way, the crud file is generated. now let's take a look at the crud of yii. On the page, enter http: // localhost/yiiphp/index. php? R = User. You can see the effect ,:

Because no information has been added to the database, the result is not displayed. you can click "create User" on the right to add a message. you can also check whether the database has been successfully added. After adding it, I believe you all know the crud of yii and give the last one.

This page shows the addition, deletion, modification, and query of yii, which is what we call crud.

Bytes. If you do not know, you can leave a message for me. First, find the configuration file of our wen project...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.