Yii framework, adding and deleting sections, SQL

Source: Internet
Author: User
Yii frame, delete and change, SQL
1. $sql = "INSERT INTO Tbl_user (' id ', ' username ', ' password ') VALUES (null, ' alu ', ' 123 ');
2. $sql = "SELECT * from Tbl_user where id=1;
3. $sql = "Update tbl_user set password=" 123456 "where id=6";
4. $sql = "Delete from tbl_user where id=6;";
Set character encoding
mysql_query ("Set names UTF8");
$result =mysql_query ($sql) or Die (' SQL statement error, the system gives the hint is: '. mysql_error ());

5. $num = Mysql_num_rows ($result) and $num=mysql_fetch_array ($result);
How should the above statement be written in the YII framework? [/color] [/color] SQL Yii Data deletion and modification Frame

Share to:


------Solution--------------------
The UTF8 encoding is written to the configuration file main.php:
' DB ' =>array (
' connectionString ' = ' mysql:host=localhost;dbname=test ',
' Emulateprepare ' = true,
' Username ' = ' root ',
' Password ' = ' 123 ',
' CharSet ' = ' utf8 ',//Set code here
' Tableprefix ' = ' tbl_ ',
),
In the controller:
$conn =yii::app ()->db;
$command = $conn->createcommand ();
Direct Write statements:
$command->text= ' select * from {{user}} where id=1 ';
$dataReader = $command->query ();
Read data:
foreach ($dataReader as $row)
{echo $row [' name '];}

The INSERT, UPDATE, and DELETE operation statements are similar in wording to the above, but with execute:
$rowCount = $command->execute (); Returns the number of rows affected;
------Solution--------------------
Http://www.yiiframework.com/doc/guide/1.1/zh_cn/database.arr
The Chinese Manual of Yii official website!
Take a look at the field and then the basic will be!
------Solution--------------------
To learn about the ActiveRecord and model of Yii, Yii has a relevant method for database operations. Suggest a look at the manual. Recommended Sites HTTP://WWW.YIIFRAMEWORK.COM/DOC/GUIDE/1.1/ZH_CN
------Solution--------------------
Recommended to see http://www.yiibook.com, the third one seems to have been translated
It's customary to use YII. DB Migration for database design and basic data warehousing
Or just build a table and use the GII to generate the appropriate crud

  • 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.