gpt4 book ai didi

Propel - 没有为数据库定义连接 "default"

转载 作者:行者123 更新时间:2023-12-02 03:17:03 26 4
gpt4 key购买 nike

我正在努力获取连接数据库的动力。我使用 propel reverse "..." 创建了类映射和表映射,并创建了以下结构:

Solution Structure

propel.ini

[propel]

# A better Pluralizer
propel.builder.pluralizer.class = builder.util.StandardEnglishPluralizer

propel.xml

<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
<config>
<propel>
<general>
<project>PHP-PlayArea</project>
<version>2.0.0-dev</version>
</general>
<database>
<connections>
<connection id="default">
<adapter>mysql</adapter>
<classname>Propel\Runtime\Connection\ConnectionWrapper</classname>
<dsn>mysql:host=localhost;dbname=test</dsn>
<user>me</user>
<password>blahblahblah</password>
<settings>
<charset>utf8</charset>
</settings>
</connection>
</connections>
</database>
<runtime>
<defaultConnection>default</defaultConnection>
<connection>default</connection>
</runtime>
<generator>
<defaultConnection>default</defaultConnection>
<connection>default</connection>
</generator>
</propel>
</config>

Propel.php

<?php namespace propel;

use Propel\Runtime\Propel;

Propel::init("../propel/propel.xml");

我的以下单元测试失败了:

// Include the main Propel script
require_once '../propel/Propel.php';

require_once '../propel/Base/Users.php';
require_once '../propel/Map/UsersTableMap.php';
require_once '../propel/Users.php';

use propel\Users;

const name = 'gareth';

class PropelTests extends \PHPUnit_Framework_TestCase {
public function testAddUser()
{
// create a user ?
$user = new Users();
// brings back an empty config
$manager = new ConfigurationManager();
//Get the array of runtime configured connections
$connections = $manager->get();

// *** fails here ***
// test connections
$con = Propel::getWriteConnection(UsersTableMap::DATABASE_NAME);
$con = Propel::getReadConnection(UsersTableMap::DATABASE_NAME);

输出;

C:\wamp\bin\php\php5.5.12\php.exe -dxdebug.remote_enable=1 -dxdebug.remote_mode=req -dxdebug.remote_port=9000 -dxdebug.remote_host=127.0.0.1 C:\Users\gareth\AppData\Local\Temp\ide-phpunit.php --no-configuration Tests\PropelTests C:\Development\PHP-PlayArea\Tests\Propel.Tests.php
Testing started at 11:40 ...
<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
<config>
<propel>
<!-- full config as above -->
</propel>
</config>

No connection defined for database "default". Did you forget to define a connection or is it wrong written?
C:\Development\PHP-PlayArea\vendor\propel\propel\src\Propel\Runtime\ServiceContainer\StandardServiceContainer.php:279
C:\Development\PHP-PlayArea\vendor\propel\propel\src\Propel\Runtime\ServiceContainer\StandardServiceContainer.php:355
C:\Development\PHP-PlayArea\propel\Base\Users.php:655
C:\Development\PHP-PlayArea\Tests\Propel.Tests.php:29

有什么想法吗?我有点困惑...我的配置看起来不错,但显然不是。

更新:2015/07/06 13:01:调试后,它看起来像是因为找不到连接管理器而爆炸了

Runtime propel variables

最佳答案

我刚刚学习 Propel,并且遇到了完全相同的问题。

我尝试做你在这里所做的事情:

Propel::init("../propel/propel.xml");

所做的只是包含文件并将内容打印到输出中,就像在输出中一样。

我终于通过有效地将 Propel.php 替换为:

<?php

use Propel\Common\Config\ConfigurationManager;
use Propel\Runtime\Connection\ConnectionManagerSingle;
use Propel\Runtime\Propel;

// Load the configuration file
$configManager = new ConfigurationManager( '../propel/propel.xml' );

// Set up the connection manager
$manager = new ConnectionManagerSingle();
$manager->setConfiguration( $configManager->getConnectionParametersArray()[ 'default' ] );
$manager->setName('default');

// Add the connection manager to the service container
$serviceContainer = Propel::getServiceContainer();
$serviceContainer->setAdapterClass('default', 'mysql');
$serviceContainer->setConnectionManager('default', $manager);
$serviceContainer->setDefaultDatasource('default');

希望这有帮助

关于Propel - 没有为数据库定义连接 "default",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31243863/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com