thinkphp operation of the database

Source: Internet
Author: User

View thinkphp Full Development manual 3.1

Edit the configuration file first

thinkphp, this database is not going to change.

A new confluence (UTF8) database was created yesterday

So just use it to learn about it, because just set up a database, there is no table, and the situation may not be the same as the manual, then Baidu a bit

<?PHPreturn Array(    //' Config item ' = ' config value '//' USERNAME ' + ' admin ',//assignment//database configuration information' Db_type ' = ' mysql ',//Database Type' db_host ' = ' localhost ',//Server Address' Db_name ' = ' confluence ',//Database name' Db_user ' = ' root ',//User name' Db_pwd ' = ' root ',//Password' Db_port ' = 3306,//Port' Db_prefix ' = ' think_ ',//database table prefix//other project configuration Parameters//...);?>
Curd operation Creation (create), update, read (read), deletion (delete)

Probably looked at, specific to the field, for the table or column did not explain, I did not look carefully ...

On the field ...

Examples of use are:

  1. $User = M("User"); //Instantiate User Object
  2. $data[' name '] = ' thinkphp ';
  3. $data[' email '] = ' [email protected] ';
  4. $User, add($data);

I changed the controller to this.

<?PHP//This class is automatically generated by the system and is intended for testing purposes onlyclassIndexactionextendsAction { Public functionindex () {//Echo ' Hello World ';        echo C (' username '); $this->display ();        $User= M ("user");//instantiating a User object$data[' name '] = ' thinkphp ';$data[' email '] = ' [email protected] ';$User->add ($data); }}

Run

Error

Access denied for user ' root ' @ ' localhost ' (using Password:no) error location

file:d:\www\myapp\thinkphp\lib\driver\db\dbmysql.class.php line:58

ThinkPHP3.1.3 {Fast & simple OOP PHP Framework}--[WE CAN do IT JUST THINK]

Baidu a bit

Said the password is wrong, modified a bit ' this symbol will not be an error

Look at the database.

There's nothing.

Modify the code, as if the logic is wrong ...

and changed the symbols again.

Did echo under Hello ever run?

Hello, come out.

Table prefix ... Add a think_.

All right... Finally done ... Distracted by ...

Let's do it again.

Structure the database First

Configure first

And then introduced the M syntax from the controller, and the admin table was directly operated, this is the model

All right...

Conflu ... Below this library is the Think_admin table

There is a column below the Think_admin table, which is named after admin

Column has the data I just added 888880000 ...

$User = M ("admin"); Instantiate the Admin object, on the Think_admin table

$data [' admin '] = ' 888880000 ';//corresponding to the admin column

thinkphp operation of the database

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.