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:
- $User = M("User"); //Instantiate User Object
- $data[' name '] = ' thinkphp ';
- $data[' email '] = ' [email protected] ';
- $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