2

I am trying to connect my database with MySQL, but I have the following error:

[Doctrine \ DBAL \ Exception \ ConnectionException]    An exception occured in driver: SQLSTATE [HY000] [2002] Connection refused

I have my project in the following path (I'm using OS X Capitan): /Applications/ XAMPP/htdocs/Projects/Cupon. I'm trying to complete the get and set methods automatically with the command: php app/console doctrine:generate:entities TiendaBundle.

Class code (Project/Cupon/src/Cupon/TiendaBundle/Entity/Tienda.php):

<?php

namespace Cupon\TiendaBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/** @ORM\Entity */

class Tienda
{

  /**
  * @ORM\Id
  * @ORM\Column(type="integer")
  * @ORM\GeneratedValue
  */
  protected $id;

  /** @ORM\Column(type="string", length=100) */
  protected $nombre;

  /** @ORM\Column(type="string", length=100) */
  protected $slug;

  /** @ORM\Column(type="string", length=10) */
  protected $login;

  /** @ORM\Column(type="string", length=255) */
  protected $password;

  /** @ORM\Column(type="string", length=255) */
  protected $salt;

  /** @ORM\Column(type="text") */
  protected $descripcion;

  /** @ORM\Column(type="text") */
  protected $direccion;

  /**
   * @ORM\ManyToOne(targetEntity="Cupon\CiudadBundle\Entity\Ciudad")
   * @ORM\JoinColumn(name="ciudad_id", referencedColumnName="id")
   */
  protected $ciudad;

}

I have a database called "symfony" in MySQL (XAMPP 5.6.3) and my configuration file in Symfony is as follows:

parameters:
    database_driver: pdo_mysql
    database_host: 127.0.0.1
    database_port: null
    database_name: symfony
    database_user: root
    database_password: '123'
    mailer_transport: smtp
    mailer_host: 127.0.0.1
    mailer_user: null
    mailer_password: null
    locale: en
    secret: c11eccf2a788b331cb9548ff4106c7461

I don't know how I can connect my project Symfony with my database in phpmyadmin.

8
  • Are you sure your configuration file is ok? why are you using null for port property? Commented Oct 17, 2015 at 9:59
  • Alireza, I think so, I also used the port 3306, but I have the same problem, I've tried a thousand different ways but can not connect, you might help me a list of steps to make the connection phpmyadmin-symfony, thanks Commented Oct 17, 2015 at 10:09
  • 2
    Is the mysql service running? Did you try to replace 127.0.0.1 to localhost? Commented Oct 17, 2015 at 10:15
  • Iago, the service is running, If I change the port to localhost I have a different error: [Doctrine\DBAL\Exception\ConnectionException] An exception occured in driver: SQLSTATE[HY000] [2002] No such file or directory Commented Oct 17, 2015 at 10:27
  • 1
    Try to set the unix_socket as in this tutorial: stackoverflow.com/questions/19629932/… Commented Oct 17, 2015 at 20:50

1 Answer 1

2

I hope you have your problem already solved, if not my solution may help you.

I had a very similar problem, but I was using MAMP, I solved my problem changing the configuration of the pdo_mysql.default_socket in the /etc/php.ini.

Why? I used terminal to create the database with

php app/console doctrine:database:create

and I use MAMP to test the site.

So, the problem, terminal was using a diferent pdo_mysql.default_socket than MAMP.

MAMP uses the config from

/Applications/MAMP/bin/php/php5.3.6/conf/php.ini

and terminal use the

/etc/php.ini

My solution:

change in my /etc/php.ini the line

pdo_mysql.default_socket=/var/mysql/mysql.sock

with:

pdo_mysql.default_socket=/Applications/MAMP/tmp/mysql/mysql.sock

Also I change my default zone:

date.timezone = "Europe/Bucharest"

I hope, this could help you doing something simmilar but now using your XAMMP socket.

Sorry for my English.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks this helped me, in my case I had to do sudo find / -name mysql.sock to find where it was for my xampp installation, then I followed your directions and it worked! Some things to note is for some reason my php.ini file said it was located in /etc/ but was not, so I had to copy one there to get it to work. Hope this helps someone.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.