Connection error: SQLSTATE[HY000] [2002] cakephp bake model and template - database

( macOS Catalina / PHP 7.4.2 / 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 : I already added export PATH=/Applications/MAMP/bin/php/php7.4.11/bin:$PATH to ~/.bash_profile
Same error on CakePHP3. Any help?

Related

heroku pg:push error with unexpected arguments - how to fix?

I am facing an issue when trying to run the command heroku pg:push postgres DATABASE_URL --app pyprodjangompz.
I get an error message saying
pg_dump: error: connection to server at "localhost" (::1), port 5432 failed: FATAL: password authentication failed for user "Usuario"
However, "Usuario" is not the name of my user in the local database. In my Docker information, it shows that the user name is "pythonpro" with password "pythonpro".
How can I resolve this issue and push my local database to Heroku?

An docker container in Azure Pipelines of an API (DRF) fails to access secondary DB SQL-SERVER only in unittesting

In my dev and production environment a dockerized DRF-API runs well. But when this very same code is built in Azure Pipelines for CI/CD, the container fails to establish connection to the SQL-SERVER which is used to query data (no primary DB of API) in the TEST step.
AzPipeline step to build the container:
- task: Docker#2
inputs:
command: build
Dockerfile: '**/Dockerfile'
containerRegistry: reg
repository: $(repo)
tags: $(imageTag)
displayName: 'Build Docker'
AzPipeline to run the container and the test:
- script: |
docker run --name $(test_container) -p 8000:8000 $(name)/$(name2):dev &
docker start $(test_container)
sleep 10
docker exec $(test_container) python src/manage.py test myapp --no-input --verbosity=3
I get the error:
Adding permission 'Permission object (49)
Adding permission 'Permission object (50)
Adding permission 'Permission object (51)
Adding permission 'Permission object (52)
Creating test database for alias 'my_sql_server' ('test_my_SQL_DB')...
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/django/db/backends/base/base.py", line 216, in ensure_connection
self.connect()
File "/usr/local/lib/python3.7/site-packages/django/db/backends/base/base.py", line 194, in connect
self.connection = self.get_new_connection(conn_params)
File "/usr/local/lib/python3.7/site-packages/sql_server/pyodbc/base.py", line 307, in get_new_connection
timeout=timeout)
pyodbc.OperationalError: ('08001', '[08001] [FreeTDS][SQL Server]Unable to connect to data source (0) (SQLDriverConnect)')
I used this image for the Docker file:
FROM nickgryg/alpine-pandas:latest
This is the configuration for the ODBC:
[FreeTDS]
Description=FreeTDS Driver
Driver=/usr/lib/libtdsodbc.so
TDS_Version=7.4
Any idea?
Seems that you need to add following entry in /etc/freetds/freetds.conf
[<sql details>]
host = <host of the sql server>
port = <port of the sql server>
tds version = 7.4

Database driver not found in parameters.yml in Symfony 2

i am newbie at Symfony , i just created a new Symfony 2.8 project using this command
$ composer create-project symfony/framework-standard-edition ecommerce "2.8.*"
the project is successfully created but since i have to work with pdo_mysql
in the configuration file parameters.yml i didn't find the " database_driver: pdo_mysql "
the database driver is not mentioned at all ! should i just add it manually in parameters.yml or how can i automatically generate it ?
Notice : PDO_Mysql is already installed and my PHP version is 5.6.31
this my parameters.yml file :
parameters.yml :
# This file is auto-generated during the composer install
parameters:
database_host: 127.0.0.1
database_port: null
database_name: symfony
database_user: root
database_password: null
mailer_transport: smtp
mailer_host: 127.0.0.1
mailer_user: null
mailer_password: null
secret: ThisTokenIsNotSoSecretChangeIt

Connecting to Cloud SQL Proxy with PDO

I'm following this tutorial except that I do not wish to use Silex.
I have set up a Cloud SQL Second Generation instance and a local proxy, which I can successfully connect to using SQL Workbench. This is the code I'm using to connect with:
define('DBH_SOCKET', '/cloudsql/project-***:us-east1:instance-****');
define('DBH_NAME', 'testdb');
define('DBH_USER', 'root');
define('DBH_PASSWORD', '****');
$pdo = "mysql:unix_socket=".DBH_SOCKET.";dbname=".DBH_NAME.";charset=utf8";
try {
$db = new PDO($pdo, DBH_USER, DBH_PASSWORD);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e){
echo 'Connection failed: ' . $e->getMessage();
}
echo '<br />';
if($db) echo 'YAY'; else echo 'NAY';
It works absolutely fine when I deploy the app an visit project-***.appspot.com, but the connection fails when I try to work locally.
Connection failed: SQLSTATE[HY000] [2002] No such file or directory.
I know this question has been asked before in various contexts, but none of their solutions are working for me or don't directly apply. I have added this to my app.yaml file with no change in results:
env_variables:
# Replace project, instance, database, user and password with the values obtained
# when configuring your Cloud SQL instance.
MYSQL_DSN: mysql:unix_socket=/cloudsql/project-****:us-east1:instance-****;dbname=testdb
MYSQL_USER: root
MYSQL_PASSWORD: '****'
beta_settings:
cloud_sql_instances: "project-****:us-east1:instance-****"
Why can't I connect locally using PDO when I can connect locally using my SQL client?

Error setting multiple db symfony 2.5

i'm trying to set 2 databases to my symfony 2.5 project, but got this error:
Fatal error: Uncaught exception 'Symfony\Component\DependencyInjection\Exception\InvalidArgumentException' with message 'The service definition "doctrine.dbal.default_connection" does not exist.' \services\vendor\symfony\symfony\src\Symfony\Component\DependencyInjection\Compiler\ReplaceAliasByActualDefinitionPass.php on line 48
Symfony\Component\DependencyInjection\Exception\InvalidArgumentException: The service definition "doctrine.dbal.default_connection" does not exist. in services\vendor\symfony\symfony\src\Symfony\Component\DependencyInjection\ContainerBuilder.php on line 867
Symfony\Component\DependencyInjection\Exception\InvalidArgumentException: Unable to replace alias "doctrine.dbal.default_connection" with "database_connection"
Here is my doctrine definition config.yml
doctrine:
dbal:
default_connection: default
connections:
default:
driver: pdo_mysql
host: localhost
port: ~
name: db1
user: root
password: ~
log:
driver: pdo_mysql
host: localhost
port: ~
name: db2
user: root
password: ~
Any suggestion?
The error message Unable to replace aliaswhen fidling with multiple databases hints to a typo in your configuration.
Double check your configuration using this reference: http://symfony.com/doc/current/cookbook/doctrine/multiple_entity_managers.html

Resources