PHP yii Framework Web Project Connection database and CRUD Operations _php Tutorial

Source: Internet
Author: User
Tags yii
The previous article describes how to configure the Yii framework, so we'll learn about the crud operations of Yii. Do not know the friend can give me a message.

First, we find the configuration file for our Wen project: \yiiphp\protected\config it has three pages and opens its main.php

The page effect we were just starting to see

Here we change the title of the project to "My PHP project"; Here is a main.php modified

Modify the gray section of line tenth to "My PHP project" so that we have successfully modified the title,

Next we set up a database to connect to PHP, such as I set up a MySQL database called "yiitest", then there is a "user" table, the table contains two fields, the following code:

mysql> CREATE DATABASE Yiitest; Query OK, 1 row Affected (0.00 sec) mysql> use yiitest;database changedmysql> CREATE TABLE user (    ID int pri Mary Key auto_increment,    name varchar, NOT NULL,    pwd varchar (+) not NULL); Query OK, 0 rows affected (0.06 sec)


So our database is built, we continue to modify the main.php configuration file, first give the original configuration,

We commented out 50 to 52 lines, then released 55 to 61, and changed the 56 line of Dbname= "testdrive" into Dbname= ' yiitest '. There are 58 to 59 lines you look at the change, because my database is no password, so I ignore it, now give the modified:

So our database connection is complete (temporarily not seeing the effect), and then we continue to configure the GII, leaf out, we give the main.php configuration artwork:

All we have to do is release 24 to 29 lines of code and put 26 lines of "password ' = ' = '" Enter Your password ' change to be what you want like ' password ' = ' password ', modified configuration

So we basically put main.php file configuration complete, now we can look at the effect, open Browser input: http://localhost/yiiphp/index.php?r=gii, login You just set the password, display <喎?http: www.bkjia.com="" kf="" ware="" vc="" "="" target="_blank" class="keylink"> vcd4kpha+ PGltZyBzcmM9 "http://www.2cto.com/uploadfile/Collfiles/20140214/20140214084303187.jpg" alt= "\" >

, we click on the third hyperlink---model Generator It means to build the program, click on it and fill in the user table of our database

Click Generate to generate the program's class file directly. Below we click the second crud Generator hyperlink, the class file just generated, called "User", click the Preview button, and then click the Generate button, so that our crud files are generated, and now we look at Yii crud. We enter http://localhost/yiiphp/index.php?r=User on the page. You can see the effect:

Since the database has not been added information it shows no results found, we can click on the right of the Create User to add a message, you can also view the database to see if there is no data to add success. After adding, I'm sure you all know the crud of Yii and give the last one.

This page gives the Yii additions and deletions, which is what we call crud.

http://www.bkjia.com/PHPjc/735887.html www.bkjia.com true http://www.bkjia.com/PHPjc/735887.html techarticle The previous article describes how to configure the Yii framework, so we'll learn about the crud operations of Yii. Do not know the friend can give me a message. First, we find the configuration file for our Wen project ...

  • Related Article

    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.