Asked  7 Months ago    Answers:  5   Viewed   31 times

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 AcmeNewsBundleEntity;

use DoctrineORMMapping as ORM;

/**
 * @ORMEntity
 * @ORMTable(name="articles")
 */
class Article
{
    /**
     * @ORMId
     * @ORMColumn(type="integer")
     * @ORMGeneratedValue(strategy="AUTO")
     */
protected $id;

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

/**
 * @ORMColumn(type="text")
 */
protected $body;

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

/**
 * @ORMColumn(type="date")
 */
protected $date;
}
?>

 Answers

91

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!

Wednesday, March 31, 2021
 
NaeiKinDus
answered 7 Months ago
94

Edit - If the services.json file does not exist, run php artisan serve and then stop to forcibly create the file. See: laravel services.json not created

Edit - updated answer to explain each command.

First, ignore the $ at the beginning of each command. These are to indicate that the commands are executed in Terminal.

To find your username, if you don't already know it, run:

$ whoami

For me, this would output rob.

Next we want to change the ownership (chown) of the services.json file. We set the owner to your username (in my case rob) and the group to _www, which is the user MAMP runs as.

$ sudo chown rob:_www /Applications/MAMP/htdocs/code/bheng/md-bheng/bootstrap/cache/services.json

Next we want to change the ownership (chown) of the storage directory. We again set the owner to your username (in my case rob) and the group to _www. You may also notice the -R option. This will execute this command recursively through all of the subdirectories contained within the storage directory.

$ sudo chown -R rob:_www /Applications/MAMP/htdocs/code/bheng/md-bheng/storage

Finally, we want to change the permissions for individual files and directories within the storage directory. The following commands will find within the storage directory, all directories (-type d) or all files (-type f) and execute the command following -exec.

$ sudo find /Applications/MAMP/htdocs/code/bheng/md-bheng/storage -type d -exec chmod 775 {} ;
$ sudo find /Applications/MAMP/htdocs/code/bheng/md-bheng/storage -type f -exec chmod 664 {} ;

The commands we're executing will change mode (chmod) for each directory or file. Read this to learn more about permissions. I've linked to Wikipedia, because it's explains things quite simply. There are likely better resources out there.

Essentially however, 775 will grant read, write and execute permissions on the directories. 664 will grant read and write permissions on the files.

Wednesday, March 31, 2021
 
DilbertDave
answered 7 Months ago
14

I found a workaround for this that I explain here. Essentially, Doctrine strips cross-database foreign keys by default because not all database systems support it, but you can disable it by commenting out some code in the Doctrine library.

Wednesday, March 31, 2021
 
SheppardDigital
answered 7 Months ago
62

According to your question the uploads folder is in /var/www/html, however going by the error message it is trying to upload into /var/www/html/test/uploads which doesn't exist

Either you need to fix the code to upload to the correct path, or you need to create an uploads directory in the test directory

Wednesday, March 31, 2021
 
Yarin
answered 7 Months ago
46

You're doing it right -- it's just slow, because the added abstraction of the ORM means you can't make the sorts of optimizations you'd like.

That said, the EntityManager does get slow on transactions that large. If you don't absolutely need them all in one big transaction, you can probably get more performant code by flush()ing and then clear()ing the EM every 20-200 iterations of your loop.

If that doesn't get you enough performance, the only alternative that I can think of is to revert to custom code that runs custom SQL directly against your DBMS.

I know this isn't a great answer, but at least I can tell you that you're not crazy.

------ edit ------

From official Doctrine2 article on Batch processing:

Some people seem to be wondering why Doctrine does not use multi-inserts (insert into (...) values (...), (...), (...), ...

First of all, this syntax is only supported on mysql and newer postgresql versions. Secondly, there is no easy way to get hold of all the generated identifiers in such a multi-insert when using AUTO_INCREMENT or SERIAL and an ORM needs the identifiers for identity management of the objects. Lastly, insert performance is rarely the bottleneck of an ORM. Normal inserts are more than fast enough for most situations and if you really want to do fast bulk inserts, then a multi-insert is not the best way anyway, i.e. Postgres COPY or Mysql LOAD DATA INFILE are several orders of magnitude faster.

These are the reasons why it is not worth the effort to implement an abstraction that performs multi-inserts on mysql and postgresql in an ORM.

Also there is a significant difference in performance when using remote vs local database as overhead of sending each query to remote server is quite large. The overhead is much lower while using local database thanks to transactions and DB optimizations. (e.g. 70sec lowered to 300ms in the case of example in the question)

Thursday, July 29, 2021
 
Amber
answered 3 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :