Laravel Database Connectivity Issues

Source: Internet
Author: User

1. Modify the configuration file/.nev

db_host=127.0.0.1//Database address db_port=3306//Database port Db_database=database//Database name Db_username=root//Database account Db_pas Sword=root//Database Password

2. Start testing If the connection is successful

The/app/http/routes.php routing code is as follows (can be customized)

Route::get (' dbtest ', ' admin\[email protected] ');

3. New Indexcontroller Controller

The/app/http/controllers/indexcontroller controller code is as follows (can be customized)

<?phpnamespace app\http\controllers\admin;use illuminate\http\request;use app\http\requests;use App\Http\ Controllers\controller;use Illuminate\support\facades\db;class Indexcontroller extends Controller{public function         DBCC () {$pdo =db::connection ()->getpdo ();   DD ($PDO); }}

4. Browse the Access test

Browser access Http://127.0.0.1/index.php/dbtest successful prompts such as

pdo {#123     intransaction: false  attributes: {     case: natural    errmode: exception    autocommit:  1    PERSISTENT: false    DRIVER_NAME:  "MySQL"      SERVER_INFO:  "uptime: 3026  threads: 4  questions:  476  slow queries: 0  opens: 42  flush tables: 1   open tables: 1  queries per second avg: 0.157 "     ORACLE_NULLS: NATURAL    CLIENT_VERSION:  "mysqlnd 5.0.11-dev -  20120503 -  $Id:  f373ea5dd5538761406a8022a4b8a374418b240e $ "     server_version:  "5.5.40"     STATEMENT_CLASS: array:1 []     connection_status:&nBSP; " 127.0.0.1 via tcp/ip "&NBSP;&NBSP;&NBSP;&NBSP;DEFAULT_FETCH_MODE:&NBSP;BOTH&NBSP;&NBSP;}}

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M00/87/AD/wKioL1ffr2_jumOQAAA3HooQqas456.png "title=" D@KBXM _%h4pvvi51ggi%myl.png "alt=" Wkiol1ffr2_jumoqaaa3hooqqas456.png "/>

Encounter frequently asked questions;

1. If your database table has a prefix how to handle

1.1/config/database.php Find the following code

       ' MySQL '  => [              ' driver '     =>  ' MySQL ',              ' host '       => env (' Db_host ',   ' localhost '),             ' database '    => env (' db_database ',  ' Forge '),              ' username '   => env (' db_username ',  ' Forge '),              ' password '   => env (' Db_password ',  '),              ' charset '    =>  ' UTF8 ' ,             ' collation '  =>  ' utf8_ Unicode_ci ', &NBSP;&NBSP;&Nbsp;          ' Strict '     => false,              ' engine '     =>  null,        ],

   1.2 modified to the following code

         ' MySQL '  => [              ' driver '  =>  ' MySQL ',              ' host '  => env (' db_host ',  ' localhost '),              ' Port '  => env (' db_port ',  ' 3306 '),              ' database '  => env (' db_ DATABASE ',  ' Forge '),             ' username '  => env (' db_username ',  ' Forge '),              ' password '  => env (' Db_password ',  '),              ' prefix '  => env (' db_prefix ',  '),              ' charset '  =>  ' UTF8 ',              ' collation '  =>  ' utf8_unicode_ci ',              ' Strict '  => false,              ' engine '  => null,        ],

1.3 Configuration file/.nev modified to the following code

db_host=127.0.0.1//Database address db_port=3306//Database port Db_database=database//database name Db_prefi X=unics_//database table prefix name db_username=root//Database account Db_password=root//Database Password


This article is from the "itunics" blog, make sure to keep this source http://unics.blog.51cto.com/11776952/1854165

Laravel Database Connectivity Issues

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.