ZF-8217: Unable to use Zend_Application_Resource_Session with xml configuration
Description
Before migrating my code to Zend Application, I previously had my session configured per
http://framework.zend.com/manual/en/…
Using a PostgreSQL database with the following table structure.
CREATE TABLE "session" ( session_id character(32) NOT NULL, save_path character varying(32) NOT NULL, "name" character varying(32) NOT NULL DEFAULT ''::character varying, modified integer, lifetime integer, session_data text, CONSTRAINT session_pk PRIMARY KEY (session_id, save_path) ) WITH ( OIDS=FALSE ); ALTER TABLE "session" OWNER TO ami;
This worked fine without any issues.
However when trying to use Zend Application with Zend_Application_Resource_Session
I get the following error.
Fatal error: Uncaught exception 'Zend_Db_Statement_Exception' with message 'SQLSTATE[42P01]: Undefined table: 7 ERROR: relation "session__seq" does not exist' in C:\Zend\Apache2\htdocs\projects\genscript\library\Zend\Db\Statement\Pdo.php:234 Stack trace: #0 C:\Zend\Apache2\htdocs\projects\genscript\library\Zend\Db\Statement.php(320): Zend_Db_Statement_Pdo->_execute(Array) #1 C:\Zend\Apache2\htdocs\projects\genscript\library\Zend\Db\Adapter\Abstract.php(468): Zend_Db_Statement->execute(Array) #2 C:\Zend\Apache2\htdocs\projects\genscript\library\Zend\Db\Adapter\Pdo\Abstract.php(238): Zend_Db_Adapter_Abstract->query('SELECT NEXTVAL(...', Array) #3 C:\Zend\Apache2\htdocs\projects\genscript\library\Zend\Db\Adapter\Abstract.php(799): Zend_Db_Adapter_Pdo_Abstract->query('SELECT NEXTVAL(...', Array) #4 C:\Zend\Apache2\htdocs\projects\genscript\library\Zend\Db\Adapter\Pdo\Pgsql.php(295): Zend_Db_Adapter_Abstract->fetchOne('SELECT NEXTVAL(...') #5 C:\Zend\Apache2\htdocs\projects\genscript\library\Zend\Db\Table\Abstract.php(1041): in C:\Zend\Apache2\htdocs\projects\genscript\library\Zend\Db\Statement\Pdo.php on line 234
The first thing one would think by looking at this to create a sequence, never had to do this before thought.
I went ahead and created the sequence it asked for and now I'm getting the following error.
Fatal error: Uncaught exception 'Zend_Db_Statement_Exception' with message 'SQLSTATE[42601]: Syntax error: 7 ERROR: zero-length delimited identifier at or near """" LINE 1: ..., "name", "modified", "session_data", "lifetime", "") VALUES... ^' in C:\Zend\Apache2\htdocs\projects\genscript\library\Zend\Db\Statement\Pdo.php:234 Stack trace: #0 C:\Zend\Apache2\htdocs\projects\genscript\library\Zend\Db\Statement.php(320): Zend_Db_Statement_Pdo->_execute(Array) #1 C:\Zend\Apache2\htdocs\projects\genscript\library\Zend\Db\Adapter\Abstract.php(468): Zend_Db_Statement->execute(Array) #2 C:\Zend\Apache2\htdocs\projects\genscript\library\Zend\Db\Adapter\Pdo\Abstract.php(238): Zend_Db_Adapter_Abstract->query('INSERT INTO "se...', Array) #3 C:\Zend\Apache2\htdocs\projects\genscript\library\Zend\Db\Adapter\Abstract.php(546): Zend_Db_Adapter_Pdo_Abstract->query('INSERT INTO "se...', Array) #4 C:\Zend\Apache2\htdocs\projects\genscript\library\Zend\Db\Table\Abstract.php(1056): Z in C:\Zend\Apache2\htdocs\projects\genscript\library\Zend\Db\Statement\Pdo.php on line 234
Below is my current application.xml config
<?xml version="1.0" encoding='UTF-8'?>
00
<date.timezone>UTC</date.timezone>
/../library/Bootstrap.phpBootstrapPdo_Pgsqllocalhosttestblahtestdb5432true/../data/sessionstrue864000Zend_Session_SaveHandler_DbTablesessionsession_idsave_pathname
<primaryAssignment.0>sessionId</primaryAssignment.0>
<primaryAssignment.1>sessionSavePath</primaryAssignment.1>
<primaryAssignment.2>sessionName</primaryAssignment.2>
modifiedsession_datalifetime/modulesindexindexdefaultMy_Controller_Plugin_Auth
<autoloaderNamespaces>
<autoloaderNamespaces.0>My_</autoloaderNamespaces.0>
</autoloaderNamespaces>
Comments
Posted by Dolf Schimmel (Freeaqingme) (freak) on 2009-11-04T10:19:37.000+0000
What is the php code with which it did work? Have you been able to see where why the old thing did work, and the new one doesn't (and maybe even have a patch available :D)?
Posted by Gabriel Baez (gabrielbaez) on 2009-11-04T10:30:36.000+0000
Hello, the old code was exactly what's currently in the documentation. This is exactly what I had in the bootstrap. {code:title=Bar.java|borderStyle=solid
//setup your DB connection like before //NOTE: this config is also passed to Zend_Db_Table so anything specific //to the table can be put in the config as well $config = array( 'name' => 'session', //table name as per Zend_Db_Table 'primary' => array( 'session_id', //the sessionID given by PHP 'save_path', //session.save_path 'name', //session name ), 'primaryAssignment' => array( //you must tell the save handler which columns you //are using as the primary key. ORDER IS IMPORTANT 'sessionId', //first column of the primary key is of the sessionID 'sessionSavePath', //second column of the primary key is the save path 'sessionName', //third column of the primary key is the session name ), 'modifiedColumn' => 'modified', //time the session should expire 'dataColumn' => 'session_data', //serialized data 'lifetimeColumn' => 'lifetime', //end of life for a specific record );
//Tell Zend_Session to use your Save Handler Zend_Session::setSaveHandler(new Zend_Session_SaveHandler_DbTable($config));
//start your session Zend_Session::start();
```
If I remove the session information out of the resources and setup the session in the bootstrap with the code above it which was the old way, then it works.
Posted by Gabriel Baez (gabrielbaez) on 2009-11-04T10:34:47.000+0000
and just for reference if I remove the SaveHandler information then it works.
Posted by Gabriel Baez (gabrielbaez) on 2009-11-04T10:40:01.000+0000
There seem to be similar issue but with different errors with Zend Application Resource Session
http://zendframework.com/issues/browse/ZF-6868
Posted by Ramon Henrique Ornelas (ramon) on 2009-11-10T17:35:02.000+0000
Problem to assign primary keys composed in associative array as index.
http://framework.zend.com/manual/en/…
Change for
Note the attached file.
Posted by Gabriel Baez (gabrielbaez) on 2009-11-11T06:42:25.000+0000
Hey Ramon, I used the setup that you provided and it works correctly, thanks for the help. It would be nice if the xml example was documented in the Zend Application section in case anybody else runs into the same issue.
Posted by Ramon Henrique Ornelas (ramon) on 2009-11-13T01:31:55.000+0000
Hey Gabriel, I'll mark this issue as resolved. I'll open a suggestion for improving the documentation in Zend_Application.