The example in this article describes the method of thinkphp3.x connecting to the MySQL database. Share to everyone for your reference, specific as follows:
Formula Profile: thinkphp/conf/convention.php
(1) Fill in the configuration file in the configuration information (profile: "./xmall/conf/config.php"):
Example:
<?php return
Array (
///' Config item ' => ' config value '/
* Database Setup * * * *
db_type ' => ' mysql ',// database type
' Db_host ' => ' localhost ',//server address ' db_name ' => ' Xmall ' , //Database name
' Db_user ' => ' Root ',// username
' db_pwd ' => ' 123 ',//password
' db_port ' => ' 3306 ', //Port
' db_ PREFIX ' => ' think_ ',//database table prefix
' Db_fieldtype_check ' => false, //whether field type checking
' Db_fields_ Cache ' => true, //enable field cache
' Db_charset ' => ' UTF8 ', //Database encoding defaults to UTF8
);
? >
(2) Create a table:
CREATE TABLE ' think_user ' (
' id ' int () default null,
' name ' varchar () default NULL,
' pwd ' varchar DEF Ault NULL
) Engine=innodb;
(3) Perform data insert operation to modify the IndexAction.class.php file under Lib/action, the contents are as follows:
<?php
class Indexaction extends action{
function index () {Public
function index () {
$data =array (
"id" => "1", "
name=" => "liuning",
"pwd" => "asd123"
);
M ("User")->add ($data);
>
(4) The implementation of http://localhost/xmall/index.php, the database will be a new record generation;
PS: Here recommend a few of the format of this site landscaping tools, I believe that we can use in future development:
PHP code online format Landscaping tools:
Http://tools.jb51.net/code/phpformat
JavaScript code Landscaping/compression/formatting/encryption Tools:
http://tools.jb51.net/code/jscompress
Online XML format/compression tools:
Http://tools.jb51.net/code/xmlformat
JSON Code Formatting Landscaping tool:
Http://tools.jb51.net/code/json
Online Xml/json Mutual Conversion tool:
Http://tools.jb51.net/code/xmljson
SQL code Online formatting Landscaping tools:
Http://tools.jb51.net/code/sqlcodeformat
More interested in thinkphp related content readers can view the site topics: "thinkphp Introductory Course", "thinkphp Common Methods Summary", "Smarty Template Primer" and "PHP template technology Summary."
I hope this article will help you with the PHP program design based on thinkphp framework.