Search code examples
phpmysqldoctrine-ormsymfony

Troubleshooting "No such file or directory" when running `php app/console doctrine:schema:create`


I am new to Symfony2 (beta4) and Doctrine and am having issues when i try to create the DB schema via command line.

Here's the error:

$ php app/console doctrine:schema:create

Creating database schema...

[PDOException]                                    
SQLSTATE[HY000] [2002] No such file or directory  

[ErrorException]                                                                                          
Warning: PDO::__construct(): [2002] No such file or directory (trying to connect via unix:///var/mysql/mysql.sock) 
in /Applications/MAMP/htdocs/sf-test-2/vendor/doctrine-dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php line 36

The mysql database settings are correctly inserted in the config/parameters.ini file.

And here's the Doctrine configuration in config.yml

# Doctrine Configuration
doctrine:
    dbal:
        driver:   %database_driver%
        host:     %database_host%
        dbname:   %database_name%
        user:     %database_user%
        password: %database_password%

    orm:
        auto_generate_proxy_classes: %kernel.debug%
        auto_mapping: true

And the entity (i made only one to test it)

<?php
// src/Acme/NewsBundle/Entity/Article.php
namespace Acme\NewsBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 * @ORM\Table(name="articles")
 */
class Article
{
    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
protected $id;

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

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

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

/**
 * @ORM\Column(type="date")
 */
protected $date;
}
?>

Solution

  • I fixed it by following this small tutorial: http://andreys.info/blog/2007-11-07/configuring-terminal-to-work-with-mamp-mysql-on-leopard

    [EDIT]: I modified the right php.ini and everything's working fine now.

    Now I get the following error:

    [Exception]                                                                                            
     DateTime::__construct(): It is not safe to rely on the system's timezone settings.
     You are *required* to use the date.timezone setting or the date_default_timezone_set() function.
     In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier.
     We selected 'Europe/Berlin' for 'CEST/2.0/DST' instead 
    

    Here's the date.timezone config in php.ini

    date.timezone = "Europe/Paris"
    

    I'll try to figure it out myself but if any of you know how to fix it don't hesitate to comment on this. Thanks!