Closed simodaya closed 4 years ago
Looks like you don't have a valid default connection setup in your app config.
CakePHP setup page : Database => CakePHP is able to connect to the database. After controllers created Databases data displays using view function with JSON.
It is likely that your CLI PHP runtime differs from the PHP runtime your webserver is using. Ensure that on the cli you have the correct version php -v
and that you have the mysql extensions loaded php -m | grep -i mysql
php -v
PHP 7.4.11 (cli) (built: Oct 1 2020 23:30:54) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.11, Copyright (c), by Zend Technologies
php -m | grep -i mysql
mysqli
mysqlnd
pdo_mysql
cd /usr/local/mysql
macbook@MacBooks-MacBook-Pro mysql %
mysql (CLI) is already installed
Your error indicates it's trying to connect to mysql through socket connection. Perhaps your mysql instance isn't running on your local machine.
( Apache & MySQL ) in Mamp are UP. I have access to Phpmyadmin
What i have to do PLEASE ??
Are you able to connect to mysql from a simple php script that you run on the command line?
You will get more help if you use the slack channel or https://discourse.cakephp.org/ forum.
@markstory good idea thank you, i'll try !!
php test.php PHP Warning: mysqli_connect(): (HY000/1045): Access denied for user 'root'@'localhost' (using password: YES) in /Users/macbook/Desktop/test.php on line 13
Warning: mysqli_connect(): (HY000/1045): Access denied for user 'root'@'localhost' (using password: YES) in /Users/macbook/Desktop/test.php on line 13
Ok. So until that works, CakePHP doesn't have a chance. You should also try root@127.0.0.1
as depending on configuration localhost doesn't always work.
This is a user error, not a bug. Closing then.
( macOS Catalina / PHP 7.4.11 / Homebrew and intl installed / MAMP )
1 -
./cake bake controller users
: It worked for me and display data from database with view function from UsersController created with bake.but when i do
2 :
./cake bake template users
or./cake bake model users
I get this error :
Connection to Mysql could not be established: SQLSTATE[HY000] [2002] No such file or directory
3 : when i try :
./cake bake template all
or./cake bake model all
Exception: Connection to Mysql could not be established: SQLSTATE[HY000] [2002] No such file or directory In [/Applications/MAMP/htdocs/cake4/vendor/cakephp/cakephp/src/Database/Driver.php, line 107]
Error: [Cake\Database\Exception\MissingConnectionException] Connection to Mysql could not be established: SQLSTATE[HY000] [2002] No such file or directory in /Applications/MAMP/htdocs/cake4/vendor/cakephp/cakephp/src/Database/Driver.php on line 107 Exception Attributes: array ( 'driver' => 'Mysql', 'reason' => 'SQLSTATE[HY000] [2002] No such file or directory', ) Stack Trace:
/Applications/MAMP/htdocs/cake4/vendor/cakephp/cakephp/src/Database/Driver/Mysql.php:114 /Applications/MAMP/htdocs/cake4/vendor/cakephp/cakephp/src/Database/Schema/BaseSchema.php:47 /Applications/MAMP/htdocs/cake4/vendor/cakephp/cakephp/src/Database/Dialect/MysqlDialectTrait.php:65 /Applications/MAMP/htdocs/cake4/vendor/cakephp/cakephp/src/Database/Schema/Collection.php:53 /Applications/MAMP/htdocs/cake4/vendor/cakephp/cakephp/src/Database/Connection.php:400 /Applications/MAMP/htdocs/cake4/vendor/cakephp/bake/src/Utility/TableScanner.php:65 /Applications/MAMP/htdocs/cake4/vendor/cakephp/bake/src/Utility/TableScanner.php:82 /Applications/MAMP/htdocs/cake4/vendor/cakephp/bake/src/Command/TemplateAllCommand.php:60 /Applications/MAMP/htdocs/cake4/vendor/cakephp/cakephp/src/Console/BaseCommand.php:175 /Applications/MAMP/htdocs/cake4/vendor/cakephp/cakephp/src/Console/CommandRunner.php:336 /Applications/MAMP/htdocs/cake4/vendor/cakephp/cakephp/src/Console/CommandRunner.php:171 /Applications/MAMP/htdocs/cake4/bin/cake.php:12
PS : A already added
export PATH=/Applications/MAMP/bin/php/php7.4.11/bin:$PATH
to~/.bash_profile
Same error on CakePHP3, any help please ???