简体   繁体   English

如何在ubuntu中将mysql数据库连接到laravel

[英]how to connect mysql database to laravel in ubuntu

I am new bee in laravel. 我是Laravel的新蜂。 I am using ubuntu terminal. 我正在使用ubuntu终端。 I have installed laravel and created one database and one table using terminal. 我已经安装了laravel并使用终端创建了一个数据库和一个表。 Now i want to connect that database with my laravel project. 现在,我想将该数据库与laravel项目连接。 I have changed database name, username and password in app/config/database.php. 我在app / config / database.php中更改了数据库名称,用户名和密码。 But don't know the connection is establish or not. 但是不知道连接是否建立。

In database.php i have changed in mysql array: 在database.php中,我在mysql数组中进行了更改:

'mysql' => array(
            'driver'    => 'mysql',
            'host'      => 'localhost',
            'database'  => 'prac',
            'username'  => 'root',
            'password'  => 'admin',
            'charset'   => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix'    => '',
        ),

When i fetch the data from table it display pdoexception could not find drivers. 当我从表中获取数据时,显示pdoexception找不到驱动程序。 I want connection with mysql. 我想与mysql连接。

"pdoexception could not find drivers" this error seems to be you don't have php mysql extension installed in your machine “ pdoexception找不到驱动程序”此错误似乎是您的计算机中未安装php mysql扩展

Check is it installed ? 检查是否已安装? using this command dpkg --list | grep php5-mysql 使用此命令dpkg --list | grep php5-mysql dpkg --list | grep php5-mysql If this command give nothing then you don't have php5-mysql extension. dpkg --list | grep php5-mysql如果此命令不提供任何内容,则您没有php5-mysql扩展名。 You can install it using following command 您可以使用以下命令进行安装

sudo apt-get install php5-mysql

after that you have to restart your apache server for load the new extension 之后,您必须重新启动apache服务器以加载新扩展

sudo service apache2 restart

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM