This code works :
1 <?
2
5 require( '/var/www/Propel/runtime/lib/Propel.php' );
6 // Initialize Propel with the runtime configuration
7 Propel::init("/home/foo/Projects/bar/classes/orm/build/conf/myconfig-conf.php");
8 // Add the generated 'classes' directory to the include path
9 set_include_path( $_SERVER['DOCUMENT_ROOT'] . "/classes/orm/build/classes/" . get_include_path());
10
11 $PQ = new ProjectsQuery();
12 $projects = ProjectsQuery::create()->find();
13 print_r( $projects );
15
16 ?>
However, if I put this exact same code inside of a class or a function (I will use a function for this example) , I get an error, and the objects are not print_r
1 <?
2
3 require( '/var/www/Propel/runtime/lib/Propel.php' );
4 // Initialize Propel with the runtime configuration
5 Propel::init("/home/foo/Projects/bar/classes/orm/build/conf/myconfig-conf.php");
6 // Add the generated 'classes' directory to the include path
7 set_include_path( $_SERVER['DOCUMENT_ROOT'] . "/classes/orm/build/classes/" . get_include_path());
8
9 public function foo()
10 {
11 $PQ = new ProjectsQuery();
12 $projects = ProjectsQuery::create()->find();
13 print_r( $projects );
14 }
15 ?>
The error that I am getting in the log file says
[Wed Feb 08 03:03:02 2012] [error] [client x.x.x.x] PHP Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM' at line 1' in /var/www/Propel/runtime/lib/query/ModelCriteria.php:1284\nStack trace:\n#0 /var/www/Propel/runtime/lib/query/ModelCriteria.php (1284): PDOStatement->execute()\n#1 /var/www/Propel/runtime/lib/query/ModelCriteria.php(1137): ModelCriteria->doSelect(Object(PropelPDO))\n#2 /home/foo/Projects/bar/models/Projects.php(12): ModelCriteria->find()\n#3 /home/foo/Projects/bar/controllers/Projects.php(11): foo()\n#4 /home/foo/Project s/bar/project-listings.php(6): Projects->__construct()\n#5 {main}\n\nNext exception 'PropelException' with message 'Unable to execute SELECT statement [SELECT FROM ] [wrapped: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to yo in /var/www/Propel/runtime/lib/query/ModelCriteria.php on line 1287
Can anyone with more Propel ORM experience tell me how I can use propel in a class or a function. Only being able to use it in the first way that I mentioned is not going to work. And I am just using straight php. No framework or anything else.