我是Symfony2(beta4)和Doctrine的新手,尝试通过命令行创建数据库模式时遇到问题。
这是错误:
$ 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
mysql数据库设置已正确插入config / parameters.ini文件中。
这是config.yml中的Doctrine配置
# 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
和实体(我只做了一个测试)
<?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; } ?>
我通过遵循此小教程对其进行了修复:http : //andreys.info/blog/2007-11-07/configuring-terminal-to-work-with-mamp-mysql- on-leopard
[编辑]:我修改了正确的php.ini,现在一切正常。
现在我得到以下错误:
[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
这是php.ini中的date.timezone配置
date.timezone = "Europe/Paris"
我会尝试自己解决这个问题,但是如果您知道如何解决它,请立即对此发表评论。谢谢!