thinkphp3.x method of connecting MySQL database (concrete operation steps) _php instance

Source: Internet
Author: User
Tags php file php code php template smarty template

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.

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.