So, continuing on my mission to compile a functioning PHP project to a .Net dll using Phalanger, I'm once again running into problems accessing the SQLite database. At this point, it seems I'm able to create the PDO object, but when I attempt to send a command creating a table, I get a "Database is not open" error.
I create my PDO object like so:
$this->db = new \PDO('sqlite:'.$fileName, null, null, [PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]);
Next, I attempt to create a table within the db.
$this->db->exec('CREATE TABLE messages (`from` TEXT, `to` TEXT, message TEXT, id TEXT, t TEXT)');
It's at this point I get the error. I've also tried creating a PDO statement like so:
$sql = 'CREATE TABLE messages (`from` TEXT, `to` TEXT, message TEXT, id TEXT, t TEXT)';
$sth = $this->db->prepare($sql);
$sth->execute();
Same results.
I've read the PDO documentation, and there doesn't seem to be a specific command to open a database once the PDO object is created, as there is in C#. Could that be the problem? Does .Net expect a specific "open" command? That wouldn't make much sense. And the fact that there is a PhpNetPDO namespace for Phalanger, would indicate that someone has put in the time to make a working implementation.
Interestingly, the source for my error is System.Data.SQLite, which isn't directly referenced in my project.
Here's what my stack trace looks like:
bei System.Data.SQLite.SQLiteCommand.InitializeForReader()
bei System.Data.SQLite.SQLiteCommand.ExecuteReader(CommandBehavior behavior)
bei System.Data.SQLite.SQLiteCommand.ExecuteReader()
bei PHP.Library.Data.SQLitePDOStatement.ExecuteStatement()
bei PHP.Library.Data.PDOStatement.execute(ScriptContext context, Object input_parameters)
bei <^>.execute(PDOStatement , ScriptContext , Object )
bei CallSite.Target(Closure , CallSite , Object , ScriptContext )
bei System.Dynamic.UpdateDelegates.UpdateAndExecuteVoid2[T0,T1](CallSite site, T0 arg0, T1 arg1)
bei SqliteMessageStore.__construct(ScriptContext , Object number)
So, maybe the Phalanger implementation of PDO uses System.Data.SQLite.
I don't know. I'm stumped. Any good suggestions or links to examples/tutorials would be greatly appreciated.
Aucun commentaire:
Enregistrer un commentaire