此代碼的工作:爲什麼我不能在其他類或函數中使用我的Propel ORM類?
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 ?>
但是,如果我把這個完全相同的代碼類或函數內(我會用這個例子的功能),我得到一個錯誤,而對象不是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 ?>
,我在日誌文件正的錯誤說
[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
的人有更多的Propel ORM的經驗可以告訴我^ h我可以在課堂或功能中使用推進。只能以我提到的第一種方式使用它不會起作用。而我只是使用直接的PHP。沒有框架或其他任何東西。