无法使用cakephp和wampserver连接到数据库 [英] cant connect to database using cakephp and wampserver

查看:56
本文介绍了无法使用cakephp和wampserver连接到数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用64位WampServer,cakephp 3.2和win10。我有一台新计算机,需要转移cakephp项目。有一个具有所有特权的用户Root,没有密码,并且在phpmyadmin上存在数据库'aptutori_apt4'n

I am using 64bit WampServer and cakephp 3.2 and win10. I have a new computer and need to transfer a cakephp project. There is a user Root with all privileges, with no password and database 'aptutori_apt4' n exists on phpmyadmin

如果不需要数据库,则将加载项目,但这就是我得到的
错误:sqlstate [hy000] [1049]未知数据库'aptutori_apt4'
我无法连接数据库!

The project loads if it doesnt need the database but this is what I get error: sqlstate[hy000] [1049] unknown database 'aptutori_apt4' I cant connect the database!

主机设置是否错误?

 'Datasources' => [
        'default' => [
            'className' => 'Cake\Database\Connection',
            'driver' => 'Cake\Database\Driver\Mysql',
            'persistent' => false,
            'host' => 'localhost',
          
            //'port' => 'non_standard_port_number',
            'username' => 'root',
            'password' => '',
            'database' => 'aptutori_apt4',
            'encoding' => 'utf8',
            'timezone' => '+11:00',
            'flags' => [],
            'cacheMetadata' => true,
            'log' => false,

与我在phpmyadmin和app.php上的另一台计算机的设置相同。新计算机显示在phpmyadmin的数据库选项卡下的Server:Mysql:3308

It is the same settings as my other computer on phpmyadmin and app.php. The new computer shows on phpmyadmin under database tab Server:Mysql:3308

推荐答案

我认为您的问题是最近mariaDB成为了默认数据库WAMPServer中的数据库,因此mariaDB使用端口3306(几乎所有MySQL的默认端口),而MySQL正在端口3308上监听

I think your problem is that recently mariaDB became the default database in WAMPServer, so therefore mariaDB is using port 3306 (the default for almost everything MySQL) and MySQL is listening on port 3308

但是,如果要使用MySQL,简单的解决方案是是交换WAMPServer中的默认数据库,当然在WAMPManager菜单上有一个用于该数据库的工具。

However, if you want to use MySQL, the simple solution would be to swap the default database in WAMPServer, and of course there is a tool for that on the WAMPManager Menus.

Right-click Wampmanager icon -> Tools -> Invert default DBMS MariaDB <-> MySQL

现在,MySQL将使用端口3306,mariaDB将使用端口3307。

Now MySQL will use port 3306 and mariaDB will use port 3307.

现在,您的cake配置应该可以正常工作,并在端口3306上找到正确的DBMS,并因此在其中创建了数据库。

Now your cake config should work and find the correct DBMS on port 3306 and therefore the database you have created in there.

这是最安全的解决方案,因为将代码移至实时服务器时几乎肯定会将其MySQL / mariaDB配置为使用端口3306,并且您无需在配置中进行任何更改。

This is the safest solution as when you move code to a live server it will almost definitely have its MySQL/mariaDB configured to use port 3306 and you wont need to change anything in your config.

或者

您可以在此参数中放入MySQL正在监听的端口号

You could put the port number that MySQL is Listening on in this param

'port' => '3308',

但是,当站点移至Live Server时,几乎可以肯定要更改此设置,然后您的开发代码和您的实时代码将有所不同,除非您记得第一次后不传输此文件。

But you will almost definitely have to change this when the site get moved to a Live Server, and then you dev code and your live code will be different, unless you remember not to transfer this file after the first time.

哦,记住,您可以撤消此更改在默认数据库中,只需返回菜单,您上次使用的菜单应显示

Oh and remember you can reverse this change in default database, just go back to the menus and the menu you used last time should say

Right-click Wampmanager icon -> Tools -> Invert default DBMS MySQL <-> MariaDB

这样做,您将使用端口3306返回mariaDB

Do that and you are back to mariaDB using port 3306

这篇关于无法使用cakephp和wampserver连接到数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆