cant connect to database using cakephp and wampserver

孤人 提交于 2020-07-31 04:17:40

问题


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

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!

Is the host setting wrong ?

 '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,

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


回答1:


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

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

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

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

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.

Alternatively

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

'port' => '3308',

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

Do that and you are back to mariaDB using port 3306



来源:https://stackoverflow.com/questions/62831463/cant-connect-to-database-using-cakephp-and-wampserver

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!