推动sql:插入抛出错误'无法解析sqldb.map的内容'

时间:2014-08-10 18:14:58

标签: php orm propel

这些天我正试图用Propel建立一个项目。我在propelorm.org/documentation/02-buildtime.html上做了基本的'bookstore'教程,但是当我试图最终通过propel插入生成的sql代码时,为了填充数据库,会抛出以下错误:

  

[例外]无法解析“/sqldb.map”的内容。

不幸的是我不知道出了什么问题;我尽可能精确地遵循了教程。

有关我的安装的信息以及到目前为止我所做的事情:

1)使用PHP 5.4.27(启用了DOM模块,支持PDO和SPL)和MySQL 5.6.19的Localhost安装(Mac OS 10.8.5)。

2)成功解析了Composer.json:

{
    "require": {
        "propel/propel": "~2.0@dev"
     },
    "autoload": {
        "classmap": ["bookstoreDb/generated-classes/"]
     }
}

3)使用外键创建了一个schema.xml,与教程(propelorm.org/documentation/02-buildtime.html)完全相同。

4)在子文件夹'conf'中创建了一个配置文件propel.yaml,就像在教程中一样。

5)使用推进脚本生成必要的sql(propel sql:build),模型(propel model:build)和配置文件(propel config:convert)。这些命令的结果如教程中所示。

6)通过终端成功创建了数据库'bookstore'。

7)尝试通过propel sql:insert插入sql代码。现在抛出如上所述的错误:

  

[例外]无法解析“/sqldb.map”的内容。

以下是项目的 index.php

    // setup the autoloading
    require_once 'vendor/autoload.php';
    // setup Propel
    require_once 'bookstoreDb/generated-conf/config.php';

    // Here I get the parse error: parse error in ../bookstore/bookstoreDb/generated-classes/Base/Author.php on line 138
    $author = new Author();
    $author->setFirstName('Jane');
    $author->setLastName('Austen');
    $author->save();

这里是 config.php

$serviceContainer = \Propel\Runtime\Propel::getServiceContainer();
$serviceContainer->checkVersion('2.0.0-dev');
$serviceContainer->setAdapterClass('bookstore', 'mysql');
$manager = new \Propel\Runtime\Connection\ConnectionManagerSingle();
$manager->setConfiguration(array (
  'classname' => 'Propel\\Runtime\\Connection\\ConnectionWrapper',
  'dsn' => 'mysql:host=localhost;dbname=bookstore',
  'user' => 'root',
  'password' => 'password',
  'attributes' =>
  array (
    'ATTR_EMULATE_PREPARES' => false,
  ),
));
$manager->setName('bookstore');
$serviceContainer->setConnectionManager('bookstore', $manager);
$serviceContainer->setDefaultDatasource('bookstore');

哪里可能有问题?是否有其他方法来设置基本项目?我很感激每一个帮助!谢谢!

1 个答案:

答案 0 :(得分:0)

我提交了一个问题:https://github.com/propelorm/Propel2/issues/694

SqlBuildCommand uses configured sql-dir 
$manager->setWorkingDirectory($generatorConfig->getSection('paths')['sqlDir'])

SqlInsertCommand only uses the command line option 
$manager->setWorkingDirectory($input->getOption('sql-dir'));

使用正确的sql目录添加--sql-dir选项以推动sql:insert确实有效

修复已提交https://github.com/propelorm/Propel2/pull/695但尚未合并