简体   繁体   中英

CakePHP WAMP - Database Mysql connection missing

I have scoured the web for an answer but as of now have been unsuccessful. I am attempting to connect CakePHP to a database. But I keep getting the same response:

CakePHP is NOT able to connect to the database.
Database connection "Mysql" is missing, or could not be created.

Here is part of my database.php file

public $default = array(
    'datasource' => 'Database/Mysql',
    'persistent' => false,
    'host' => 'localhost',   
    'login' => 'root',
    'password' => '',
    'database' => 'cake',
    'prefix' => '',
    //'encoding' => 'utf8',
);

^I've also tried different host/login combinations based from the access privileges list in phpmyadmin.

I think one problem might be that Wampserver is finding the wrong php.ini file. It seems that it is loading the file at: "C:\\Program Files (x86)\\PHP\\php.ini" instead of something under "C:\\wamp...". How would I set it to point at the right file??

However, I had added the line "extension=php_pdo_mysql.dll" to both files and still no luck. Any help would be appreciated.

I had the exact same issue. There was no problem in the mysql database as it was accessible through phpMyadmin and other applications running on the server. The issue was caused due to the mysql port not mentioned alongwith the host. Append the port with the host like... 'host' => 'localhost:3307'.

public $default = array(
    'datasource' => 'Database/Mysql',
    'persistent' => false,
    'host' => 'localhost:3307',
    'login' => 'root',
    'password' => 'mypass',
    'database' => 'cake_todos',
    'prefix' => '',
    //'encoding' => 'utf8',
);

Now, how to know the mysql port? For that you need to go to the server configuration file.. eg the in my case it was the properties.ini file in the home directory of the wamp folder. Open the file and you will most probably find an entry like this:

mysql_port=3307 mysql_host=127.0.0.1

So, here it is, the mysql_port. Hope it helps.

First check there is database called cake in your localhost/phpmyadmin, and if that mysql use the username root and no password and also make sure you set php_mysql on the right php.ini file ( extension=php_mysql.dll ).

Second, if you think the problem is because of php.ini file location, you can set it:

  1. go to your wamp folder (C:\\wamp) and
  2. under that folder you'll find wampmanager.ini file and
  3. Find php.ini word in that file you'll get this kind of line (Type: item; Caption: "php.ini"; Glyph: 6; Action: run; FileName: "notepad.exe"; parameters: "...path here...") and locate the path and set "C:/wamp/bin/apache/apache2.2.21/bin/php.ini"

please tell me (vote) if it works. I hope it helps.

Thanks

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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