CakePHP WAMP - Database Mysql connection missing - php

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.. e.g. 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:
go to your wamp folder (C:\wamp) and
under that folder you'll find wampmanager.ini file and
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

Related

CakePHP Console Cron Database connection Error

I have a Webapp which is using the CakePHP 2.x framework. The main front-end works perfectly fine but I have some cron jobs which are run form the Cake Console. When I run these cron jobs I get the following error:
"Error: Database connection “Mysql” is missing, or could not be created"
There are several similar questions on SO (but none of the given solutions works for me. I have the following DB connection setup in the Cake config file and which works for the front-end:
public $default = array(
'datasource' => 'Database/Mysql',
'persistent' => false,
'host' => 'xxxxx.com',
'login' => 'xxxxxx',
'password' => 'xxxxxxx',
'database' => 'goalarc-dev',
'prefix' => '',
'unix_socket' => '/var/run/mysqld/mysqld.sock'
);
I added the 'unix_socket' key after reading a similar solution. My server is running on AWS and so I opened:
/etc/mysql/my.cnf
And found the socket line as follows:
socket = /var/run/mysqld/mysqld.sock
However when I browse to 'var/run/mysqld' the folder is empty when I use the command "ls -l". This would suggest to me that somethig is mis-configured. How can I find the true and valid location of mysql.sock?
A.

Cakephp installation

I have installed cakephp 2.7.5 on xampp but when I run my application I get an error message >CakePHP is NOT able to connect to the database.
Database connection "Mysql" is missing, or could not be created.< I suspect that my mysql server is not properly configured and I have particular concerns over the PDO and pdo_mysql settings in the php.ini file. How do I enable them? (I am totally lost here)Thanks in advance.
You don't mention configuring the connection, so your problem is most probably that of a missing initial database configuration.
You will obviously need to create a database (and maybe a user with sufficient permissions in that DB) before you setup the configuration. Don't mess with PDO configuration in php.ini, it should run out of the box with XAMPP.
Rename file name from database.php.default to database.php .Create a database in mysql. Open the file and change your mysql login,password and database from default variable.Then run your application.
public $default = array(
'datasource' => 'Database/Mysql',
'persistent' => false,
'host' => 'localhost',
'login' => 'user',
'password' => 'password',
'database' => 'database_name',
'prefix' => '',
//'encoding' => 'utf8',
);

Can't connect to database with laravel 5

I'm trying to connect to my mssql database with laravel 5 but it's not working. I've tried to connect with different mssql databases so it's not a firewall issue. Also my credentials are correct. I found on google that you need SQL Server Native Client 11.0 and I've already installed that.
This is my connection array in config/database.php:
'sqlsrv' => [
'driver' => 'sqlsrv',
'host' => env('nvt'),
'database' => env('nvt'),
'username' => env('nvt'),
'password' => env('nvt'),
'charset' => 'utf8',
'prefix' => '',
],
And I've set the default to "sqlsrv" :
'default' => env('sqlsrv','sqlsrv'),
But when I'm trying to create a table I receive the error:
PDOException in Connector.php line 50: could not find driver
What could be wrong???
EDIT:
I've installed pdo for sqlsrv from here:
http://msdn.microsoft.com/en-us/sqlserver/ff657782.aspx
And I added it to my php.ini file:
extension=\Installaties\php_pdo_sqlsrv_53_nts.dll
But stil I receive the error?
Try to remove the eve() method, i mean use the following method
'sqlsrv' => [
'driver' => 'sqlsrv',
'host' => 'nvt',
'database' => 'nvt',
'username' => 'nvt',
'password' => 'nvt',
'charset' => 'utf8',
'prefix' => '',
],
I ran into a similar issue. Try putting in the server info directly rather than using env. If it works, then you know Laravel is having an issue reading the .env file.
I encountered your problem the last time I tried my connection in sqlsrv. I am using xampp. Try putting yung php_pdo_sqlsrv_53_nts.dll in the ext folder, replace extension=\Installaties\php_pdo_sqlsrv_53_nts.dll with extension=php_pdo_sqlsrv_53_nts.dll and try installing odbc 11 on your computer. It worked for me but not sure why. (not an expert) if it worked good to help a fellow person and if not, sorry for the trouble. Thank you for the time reading.
You may try any of the following solutions
Check that you have entered the right connection parameters. Test by connecting to the DB with a client tool.
Make sure you have the right version of sqlsrv configured for your machine. Check the PHP logs to be sure your web server was able to load the extension correctly.
Set the port to null in your env file
As a tip, I won't advise anyone to set the connection parameters anywhere but in the .env (Setting it in config/database is a security risk).

Setting up a local version of site: config settings/issues

I've been attempting to set up a version of my website on my computer so that I stop making live updates on my website. The website runs on a PHP based CMS.
I posted a question earlier: mysql connect - Moving my website to a local host
The question was about mysql-connect - the outcome was that I connected my database to my localhost as opposed to the current live host.
Now, the local version of my site loads except all styling is gone and the nav links do not work. I suspect the answer may be to do with the same file I edited in the question above: application/config/database.php
Here is what the code looked like originally:
$config['default'] = array(
'benchmark' => TRUE,
'persistent' => FALSE,
'connection' => array(
'type' => 'mysql',
'user' => 'mywebsite',
'pass' => 'somestringoftext',
'host' => 'mywebsitecom.fatcowmysql.com',
'port' => FALSE,
'socket' => FALSE,
'database' => 'mywebsiteDB4',
Then I changed it to this:
$config['default'] = array(
'benchmark' => TRUE,
'persistent' => FALSE,
'connection' => array(
'type' => 'mysql',
'user' => 'root',
'pass' => '',// Since it's on local host there is no password right now
'host' => 'localhost',
'port' => FALSE,
'socket' => FALSE,
'database' => 'mywebsite',//this is what I called the DB I created and imported to in PHPmyadmin
It may be that this all looks correct and the issue lies elsewhere. I have a suspicion that it could be to do with the .htaccess file as, when I initially set up the site, I had issues with that, except all I had to do was set permissions. Thing is, the way the local version appears right now is very similar to how it looked when the .htaccess file was not "working".
I realize that I've just dropped a bunch of code and said "help"! I'm really stuck on where to look next. If anyone does have any ideas I'd be grateful to hear them. If any further info could help anyone with suspect ideas please let me know and I'l update.
If site loads and you can see at page data taken from database, it means, what you DB connection is OK.
Since you can't see styling and menu not works, it means what you .JS/.CSS files not loaded correctly from you local server.
You can use addon FireFox called FireBug and here "Net" tab, to see which files loaded correctly and which not. For not loaded files you will need or change path to include it in you HTML file or change files location in you local filesystem

Cake is NOT able to connect to the database. XAMPP

I'm developing on XAMPP 1.8.1 and running into issues with CakePHP not being able to connect to the database. I've looked around a bit, and others have suggested making sure pdo is enabled, and it is. I know my database settings are correct. I've checked and rechecked them, but I'm still getting:
Cake is NOT able to connect to the database.
Database connection "Mysql" is missing, or could not be created.
I've set up CakePHP multiple times before, even with XAMPP, and I've never run into this issue.
My database settings are as follows:
public $default = array(
'datasource' => 'Database/MySQL',
'persistent' => false,
'host' => 'localhost',
'login' => 'cakeuser',
'password' => '*****',
'database' => 'cake',
'prefix' => '',
//'encoding' => 'utf8',
);
Any suggestions?
Check the output of your phpinfo (). Is there a row titled PDO drivers? What does it say?

Categories