Re: [svn:PHP-Sandwich] rev 1432 - in PHP-Sandwich/trunk: . t

[email protected] (David Wheeler) Sun, 31 Jul 2005 08:43:46 -0700
Newsgroups perl.php.sandwich.dev
Message-ID <[email protected]>
On Jul 30, 2005, at 8:25 PM, David Wheeler wrote:

>> all tests pass successful.  Note new
>> new() method for instantiating objects -
>> doing so for XS routines in eval() seems unsafe.
>>
>
> What happens when the constructor is called something other than new 
> (), like DBI's connect()?

Woo! this script seems to work, although it does exit with a bus error:

#!/usr/bin/perl -w

use strict;

use PHP::Interpreter;
use DBI;

my $php = PHP::Interpreter->new;
$php->eval(q/
     $perl = Perl::getInstance();
     $dbh = $perl->call('DBI::connect', 'DBI',
                        "dbi:SQLite:dbname=dbfile", "", "");
     $dbh->do('CREATE TABLE foo (bar text)');
     $dbh->do("INSERT INTO foo values ('This is a test')");
     $sel = $dbh->prepare('SELECT bar FROM foo');
     $sel->execute();
     foreach ($sel->fetch() as $val) {
         echo "$val\n";
     }
     $sel->finish();
     $dbh->disconnect();
/);

unlink 'dbfile';

But I just love that we'll be able to show PHP folks how they can use  
solid Perl modules like DBI and DateTime in their PHP applications.  
Nice work, George, and thanks!

Best,

David