Jump to content
xisto Community
Sign in to follow this  
sonesay

Doctrine 1.2 Introduction Need help with connection issue

Recommended Posts

Hi all, I'm just starting off on learning doctrine from the official getting started guide http://docs.doctrine-project.org/projects/doctrine1/en/latest/index.html

and have gotten up to the models section. I how ever have come across a road block as the steps given previously seem to miss out something and I get an error when trying to run a script that drops and recreates a database. The error seems to be complaining about an invalid dsn yet the same connection was used in the previous steps to do the tasks etc.

 

I have looked at where I can post / request for help in IRC channels and any doctrine official forums but cant seem to find any. I was hoping someone with knowledge in doctrine here can point me to a solution. If you click on the link at the start it will take you tot the page I am currently on. The problem is when I am running the php generate.php script which throws an error when trying to drop the database. It looks as though they have neglected to supply all steps or assume we would know what to do.

 

 

Error Ouput

si2:doctrine_test sone$ php generate.php Fatal error: Uncaught exception 'Doctrine_Connection_Exception' with message 'You must create your Doctrine_Connection by using a valid Doctrine style dsn in order to use the create/drop database functionality' in /Users/sone/si3webportfolio/doctrine_test/lib/vendor/doctrine/Doctrine/Connection.php:1460Stack trace:#0 /Users/sone/si3webportfolio/doctrine_test/lib/vendor/doctrine/Doctrine/Manager.php(707): Doctrine_Connection->dropDatabase()#1 /Users/sone/si3webportfolio/doctrine_test/lib/vendor/doctrine/Doctrine/Core.php(972): Doctrine_Manager->dropDatabases(Array)#2 /Users/sone/si3webportfolio/doctrine_test/generate.php(11): Doctrine_Core::dropDatabases()#3 {main}  thrown in /Users/sone/si3webportfolio/doctrine_test/lib/vendor/doctrine/Doctrine/Connection.php on line 1460

my bootstrap.php

<?php// bootstrap.php/** * Bootstrap Doctrine.php, register autoloader specify * configuration attributes and load models. */require_once(dirname(__FILE__) . '/lib/vendor/doctrine/Doctrine.php');// ...spl_autoload_register(array('Doctrine', 'autoload'));// ...$manager = Doctrine_Manager::getInstance();$manager->setAttribute(Doctrine_Core::ATTR_AUTO_ACCESSOR_OVERRIDE, true);$manager->setAttribute(Doctrine_Core::ATTR_AUTOLOAD_TABLE_CLASSES, true);// Setting up DB connection$dsn = 'mysql:dbname=doctrine;host=127.0.0.1';$user = 'sonint99';$password = 'C2sHF9Zxq3ULXCTV';$dbh = new PDO($dsn, $user, $password);$conn = Doctrine_Manager::connection($dbh,'doctrine');Doctrine_Core::loadModels('models');//$conn = Doctrine_Manager::connection('mysql://sonint99:C2sHF9Zxq3ULXCTV@127.0.0.1/zcdev');

my generate.php

<?php// generate.phprequire_once('bootstrap.php');Doctrine_Core::dropDatabases();Doctrine_Core::createDatabases();Doctrine_Core::generateModelsFromYaml('schema.yml', 'models');Doctrine_Core::createTablesFromModels('models');

Like the error suggest its a dsn connection thing but it does not explain why my same connection works for the previous tasks on the tutorial page and I don't remember coming across any steps that required me to alter the connection. A prime example of tutorials not being clean enough to help new members start. Anyone with knowledge on connections could you please explain to me the difference between the PDO connection I made the the inline connection string i commented out

 

//$conn = Doctrine_Manager::connection('mysql://sonint99:C2sHF9Zxq3ULXCTV@127.0.0.1/zcdev');

When using the above connection string I am able to run generate.php and drop the database not but create. This is a very annoying issue and I would like to clear it up. Searching all last night came up with no fixes and only one person reported the same issue on stackoverflow but the solution given was to use the commented out connection string variant above and no further responses to whether it was the right way to do it or not and also no confirmation if it produces anymore errors like mine.

 

Edit: forget the database table names as I have both now for testing purposes. They are not an issue as I have full privileges to all on my mysql account.

Edited by sonesay (see edit history)

Share this post


Link to post
Share on other sites

Never used doctrine so i can't offer much help to you. Looking at the current condition for dead forums, i doubt if there is any active php developer is there. You should better ask this question in stackoverflow site. That site has lots of active php developers who can help you into this. I tried to search your question related info on stackoverflow but no results. So i suggest you to ask your question there.

Share this post


Link to post
Share on other sites

Yeah I was looking for an official forum where I could post my issue but nothing for doctrine. They do have a google groups mailing list though and I have made a post on there as well as stackoverflow but still no response yet. I'm currently just trying to keep busy and work on multiple projects so when I get a setback I can post my questions and continue with the other ones.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.