I try to create some entity to my Symfony projet using the console with the following command :
php app/console doctrine:generate:entity
but when i choose a name for it , i get this error :
[Doctrine\DBAL\Exception\ConnectionException] PDOException:
SQLSTATE[HY000] [2002] No connection could be made because the target
machine actively refused it
and this is my parameters.yml on my symfony project :
# This file is auto-generated during the composer install
parameters:
database_host: 127.0.0.1
database_port: 3306
database_name: symfony
database_user: root
database_password: root
mailer_transport: smtp
mailer_host: 127.0.0.1
mailer_user: null
mailer_password: null
secret: ThisTokenIsNotSoSecretChangeIt
I tried to replace 127.0.0.1 by Localhost but it still the same.
Im on Windows 7 and i use Wamp.
EDIT : My port number is 3307 ... Problem solved !
If you are using 127.0.0.1 then you need to specify a port (3306 in most cases). If you use localhost instead, the argument port will be ignored. Specifying the port number might work in your case.
It has to come from you db config: either your parameters are wrong for your db, either your db server rejects the connection even though the parameters are good.
what DBMS are you using?
Some DBMS require additional config (like Oracle).
If i were you i would first check that i am using the right pdo driver for my DBMS.
Related
I work with Symfony 3 on my first web site.
When I launch the web site locally, it work and the link with the local database is done.
But when I use the parameters of real database on OVH, I have this message :
An exception occured in driver: SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known
The two base are similar, it's a import of the local database.
I have this parameters :
# This file is auto-generated during the composer install
parameters:
database_host: e********.mysql.db
database_port: 21
database_name: e********
database_user: e********
database_password: ********
mailer_transport: smtp
mailer_host: 127.0.0.1
mailer_user: null
mailer_password: null
secret: ThisTokenIsNotSoSecretChangeIt
This is a strange behavior on OVH may not be stable on shared host: Periodically, the alias host xxx.mysql.db is reset or the ip behind it changes and the access is lost for some time. Just wait till next day.
I have installed Symfony project under MAMP htdocs project folder, which works perfect. I them moved on to create a new Boundle, I created it just fine but I found my self in troubles doctrine.....
I am following this tutorial : Tutorial Link
The part I have stumbled on in this tutorial is:
app/console doctrine:database:create
When I run this command in my terminal I get this error:
Could not create database for connection namedsymfony
SQLSTATE[HY000] [1045] Access denied for user 'root'#'localhost' (using password: NO)
Looking at this error it that I have wrong parameters to connect to database so I checked the parameters.yml.dis file and this is what i have in it:
`parameters:
database_driver: pdo_mysql
database_host: 127.0.0.1
database_port: ~
database_name: symfony
database_user: root
database_password: ~
mailer_transport: smtp
mailer_host: 127.0.0.1
mailer_user: ~
mailer_password: ~
locale: en
secret: ThisTokenIsNotSoSecretChangeIt
debug_toolbar: true
debug_redirects: false
use_assetic_controller: true`
I tried localhost instead 127.0.0.1
I tried MAMP database_port: 8889
I tried MAMP password whihc is: root
but i keep on getting the same error
also not to sure if revelant as my apache and phpmyadmi in on MAMP, but when i run this command in my terminal mysql -u root -p this is the terminal response: -bash: mysql: command not found
About the SQL login issue
Check http://localhost/phpmyadmin in the privileges panel to see if the user root has a password defined or not and if it is allowed to access mysql via localhost (or other hosts) and if it has permissions to any database.
About the MAMP issue
Since you do not have mysql installed globally, you don't have access to it from everywhere.
Your mysql is installed locally in your MAMP so you can access it using the /path-to-MAMP/bin/mysql or something similar.
I'm currently working on a website using Symfony2 and doctrine2 for the database. I did everything from this tutorial:http://tutorial.symblog.co.uk/docs/doctrine-2-the-blog-model.html
However, when I try to do this:
php app/console doctrine:database:create
I get this error:
Could not create database for connection named `CHuts_DB`
SQLSTATE[28000] [1045] Access denied for user 'rootDB'#'localhost' (using password: YES)
And this is my parameters.yml:
parameters:
database_driver: pdo_mysql
database_host: localhost
database_port: '3396'
database_name: CHuts_DB
database_user: rootDB
database_password: ***
...
database_path: null
I don't understand why it's not working. I'm fairly new to Symfony2 and I've searched a bit on internet but I couldn't find someone with the same error message as me.
In PHPMyAdmin go to:
Users -> rootDB -> Structure (check CREATE)
and save privileges of user.
I think your user and/or password aren't correct.
You can try mysql command line:
> mysql -u rootDB -p
or install adminer.php in your webserver and try to verify the account.
This solution worked for me on Mac OS X with MAMP (or MAMP Pro).
Add database.unix_socket in app/config/parameters.xml
parameters:
database.driver: pdo_mysql
database.host: localhost
database.port: 8888
database.name: my-database-name
database.user: root
database.password: root
database.unix_socket: /Applications/MAMP/tmp/mysql/mysql.sock
Add unix_socket in app/config/config.xml
# Doctrine Configuration
doctrine:
dbal:
# ...
unix_socket: "%database.unix_socket%"
I try to generate entities based on a database SQL Server 2005 with Doctrine.
Unfortunatly, when i launch my command i have an error :
[PDOException]
could not find driver
In the folder PHP\etc, drivers are OK.
In the folder (inside the project) vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver, i can see PDOSqlsrv.
Parameters.yml is configured like that :
parameters:
database_driver: pdo_sqlsrv
database_host: myHost
database_port: null
database_name: myName
database_user: user
database_password: pwd
I don't understand the problem with my configuration.
If anyone has an idea ... thanks a lot.
I'm in the process of learning Symfony2 for a project that me and some friends are taking on, and am taking a tutorial where you make a blog in Symfony2: http://tutorial.symblog.co.uk/docs/doctrine-2-the-blog-model.html
Problem
I can't seem to get Doctrine2 to work. I give the following instruction to the Terminal:
php app/console doctrine:database:create
And get the following error message:
Could not create database for connection named symfony
SQLSTATE[HY000] [2002] Connection refused
System info
I have a mac that runs Mountain lion and I use MAMP.
What I have done
I went to the config page (http://localhost/NameOfProject/web/config.php) and went to the place where you configure your database. There I put in the path, port, user, password, etc from the MAMP start page.
What I have tried
A blog I came across suggested to create a symbolic link to the the MAMP mysql socket with the following command:
sudo ln -s /Applications/MAMP/tmp/mysql/mysql.sock mysql.sock
This did not make the error go away for me.
Some of my files in symfony (if they are relevant)
From app/config/config.yml:
parameters:
database_driver: pdo_mysql
database_host: 127.0.0.1
database_port: '8889'
database_name: symfony
database_user: root
database_password: root
mailer_transport: smtp
mailer_host: 127.0.0.1
mailer_user: null
mailer_password: null
locale: en
secret: 0408312e2b9861c0c86dbb7488aceec4296054ec
database_path: /Applications/MAMP/tmp/mysql/mysql.sock
From app/config/parameters.yml:
parameters:
database_driver: pdo_mysql
database_host: 127.0.0.1
database_port: '8889'
database_name: symfony
database_user: root
database_password: root
mailer_transport: smtp
mailer_host: 127.0.0.1
mailer_user: null
mailer_password: null
locale: en
secret: 0408312e2b9861c0c86dbb7488aceec4296054ec
database_path: /Applications/MAMP/tmp/mysql/mysql.sock
The tutorial talks updating the database_* options in the parameters file located at app/config/parameters.ini. However, I don't have a parameters.ini file located in this folder! Only parameters.yml.
Edit: Solution:
I was using the wrong port number for MySql. When I used 3306 it worked.
I was using the wrong port number for MySql. When I used 3306, the standard mysql port, it worked.
(Thank you jperovic)