我是Symfony2 (beta4)和Doctrine的新手,在尝试通过命令行创建DB模式时遇到问题。
下面是错误:
$ 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 36mysql数据库设置已正确插入到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;
}
?>发布于 2011-06-08 00:27:48
我按照这个小教程解决了这个问题: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"我会试着自己解决这个问题,但如果你们中任何人知道如何修复它,请毫不犹豫地对此发表评论。谢谢!
发布于 2012-02-13 03:27:17
太晚了,但我希望它能帮助一些人。
就在今天,我遇到了类似的情况(但在其他情况下,我试图从db创建实体)。
我在parameters.ini文件中简单地将de database_host从"localhost“修改为"127.0.0.1”就解决了这个问题。
我认为我的Mysql实例仅通过TCP而不是套接字运行,因此当使用database_host="localhost“时,它会失败。
发布于 2011-06-07 16:06:29
尝试添加此行
unix_socket: /tmp/mysql.sock进入您的config.yml文件>主义> dbal,就在密码行之后。
https://stackoverflow.com/questions/6259424
复制相似问题