2015-07-06 17 views
6

Non riesco a far funzionare la connessione a un database. Ho creato mappato le classi e le mappe tabella utilizzando propel reverse "...", e ha creato la seguente struttura:Propel - Nessuna connessione definita per il database "default"

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"); 

Ho il seguente test di unità, che cade a terra:

// 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); 

uscita;

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 

Qualche idea? Sono un po 'perplesso ... La mia configurazione sembra buona, ma ovviamente non lo è.

Aggiornamento: 2015/07/06 13:01: dopo il debug questo sembra che le bombe fuori perché non gestioni connessioni potrebbe essere trovato

Runtime propel variables

+0

mai usato Propel, ma avete controllato il percorso di inizializzazione con 'Propel :: init ('/ percorso/a/mio/file '); '? –

risposta

5

Sto solo imparando Propel e stavo avendo lo stesso identico problema.

Ho provato a fare quello che hai fatto qui:

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

Tutto ciò che ha fatto è stato includere il file e stampare il contenuto all'uscita proprio come avete nella vostra uscita.

finalmente ho capito di lavoro sostituendo efficacemente la vostra Propel.php con:

<?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'); 

Spero che questo aiuti

+0

Fantastico! Grazie mille.Ora ho un ConnectionManager con cui giocare. – wonea

1

vostra manca il numero di porta nel seguito linea in propel.xml:

<dsn>mysql:host=localhost:<<port number>>;dbname=test</dsn> 

controllare anche il nome del database nel schema.xml se avete reverse engineering da uno schema esistente. Assicurati che non sia vuoto.

+0

Ho regolato sia propel.php che propel.xml con il numero di porta, ma questo non ha fatto alcuna differenza. – wonea

+0

Modificare il nome della classe in ....../DebugPDO anziché ConnectionWrapper. Quindi esegui il test e guarda cosa ottieni. – Khush

+0

Assicurati anche che ci sia un database chiamato "test" – Khush