Doctrine2 命令行工具的使用

Doctrine2压缩包的tools目录用来做一些命令行工作。但是必须从SVN上下载Doctrine2才能使用它们。假设你使用了svn上的doctrine2,根据你服务器的配置,如果针对的是mysql操作,cli-config.php修改数据库连接
$connectionOptions = array(
'dbname' => 'mydb',
'user' => 'root',
'password' => '',
'host' => '127.0.0.1',
'driver' => 'pdo_mysql',
);

然后运行php doctrine.php显示如下结果
Doctrine Command Line Interface version 2.0-DEV

Usage:
  [options] command [arguments]

Options:
  --help           -h Display this help message.
  --quiet          -q Do not output any message.
  --verbose        -v Increase verbosity of messages.
  --version        -V Display this program version.
  --color          -c Force ANSI color output.
  --no-interaction -n Do not ask any interactive question.

Available commands:
  help                         Displays help for a command (?)
  list                         Lists commands
dbal
  :import                      Import SQL file(s) directly to Database.
  :run-sql                     Executes arbitrary SQL directly from the command line.
orm
  :convert-d1-schema           Converts Doctrine 1.X schema into a Doctrine 2.X schema.
  :convert-mapping             Convert mapping information between supported formats.
  :ensure-production-settings  Verify that Doctrine is properly configured for a production environment.
  :generate-entities           Generate entity classes and method stubs from your mapping information.
  :generate-proxies            Generates proxy classes for entity classes.
  :generate-repositories       Generate repository classes from your mapping information.
  :run-dql                     Executes arbitrary DQL directly from the command line.
orm:clear-cache
  :metadata                    Clear all metadata cache of the various cache drivers.
  :query                       Clear all query cache of the various cache drivers.
  :result                      Clear result cache of the various cache drivers.
orm:schema-tool
  :create                      Processes the schema and either create it directly on EntityManager Storage Connection or generate the SQL output.
  :drop                        Processes the schema and either drop the database schema of EntityManager Storage Connection or generate the SQL output.
  :update                      Processes the schema and either update the database schema of EntityManager Storage Connection or generate the SQL output.

1. 数据库反转工程
预准备:
反转工程是从db->yml|xml->entity classes,这里使用yml作为中间媒介。
将cli-config.php行
$driverImpl = $config->newDefaultAnnotationDriver(array(__DIR__."/Entities"));
修改为:
$driverImpl = new \Doctrine\ORM\Mapping\Driver\YamlDriver(array('D:\temp\pro\export\yml'));

步骤I. 从数据库生成yml文件
php doctrine orm:convert-mapping -v --from-database yml d:\temp\pro\export\yml


步骤II. 从Yml生成entities文件
php doctrine orm:generate-entities --generate-annotations=true --update-entities=true d:\temp\pro\export\Entities

d:\temp\pro\export\yml和d:\temp\pro\export\Entities目录需要事先建立。

Draft Version

你可能感兴趣的:(sql,PHP,orm,SVN,cache)