Re: PHP SQLite connection in OpenBSD

2011-12-14 Thread Stuart Henderson
On 2011-12-13, Bentley, Dain dbent...@nas.edu wrote:
 Thanks for the help.  I'm getting a different error now:
 SQLSTATE[HY000] [1] unable to open database: /path/to/db

 Can't seem to find much on this error.  Something from the PHP website about
 having to recompile PHP from source but it's an old thread and I'd rather not
 use non-packaged third party tools if I can help it.

I think this is what you see when the database is in a non-writable
directory.



Re: PHP SQLite connection in OpenBSD

2011-12-13 Thread richardtoohey
Quoting Bentley, Dain dbent...@nas.edu:

 Hello all, I'm trying to connect to a sqlite database with PHP and I'm
 having
 an issue of driver not found. I've installed php from packages and and
 have
 installed the php_sqlite package and configured the module for apache.
 The PDO driver seems to be installed as evidenced by my php info page:
 
 SQLite support enabled
 PECL Module version 2.0-dev $Id: sqlite.c 298697 2010-04-28 12:10:10Z
 iliaa $
 SQLite Library 2.8.17
 SQLite Encoding iso8859
 
 PDO drivers sqlite2
 
 Here is the code I am using to attempt to connect
 ?php
 try {
  // connect to SQLite from PDO database
  $dbh = new PDO(sqlite:/bandwith/stats.db);
 
 }
 catch(PDOException $e)
 {
  echo $e-getMessage();//this getMessage throws an exception if any
 
 }
 ?
 
  

Does the code work OUTSIDE of Apache?

php-5.3 your-script.php

Have you considered chroot?

http://www.openbsd.org/faq/faq10.html#httpdchroot

HTH



Re: PHP SQLite connection in OpenBSD

2011-12-13 Thread Bentley, Dain
Same error when run from command-line.  I should also add this is 4.9 not 5.0.
Sorry I didn't input that info earlier.

-Original Message-
From: richardtoo...@paradise.net.nz [mailto:richardtoo...@paradise.net.nz]
Sent: Tuesday, December 13, 2011 3:35 PM
To: Bentley, Dain
Cc: misc@openbsd.org
Subject: Re: PHP SQLite connection in OpenBSD

Quoting Bentley, Dain dbent...@nas.edu:

 Hello all, I'm trying to connect to a sqlite database with PHP and I'm
 having an issue of driver not found. I've installed php from
 packages and and have installed the php_sqlite package and configured
 the module for apache.
 The PDO driver seems to be installed as evidenced by my php info page:

 SQLite support enabled
 PECL Module version 2.0-dev $Id: sqlite.c 298697 2010-04-28 12:10:10Z
 iliaa $ SQLite Library 2.8.17 SQLite Encoding iso8859

 PDO drivers sqlite2

 Here is the code I am using to attempt to connect ?php try {  //
 connect to SQLite from PDO database  $dbh = new
 PDO(sqlite:/bandwith/stats.db);

 }
 catch(PDOException $e)
 {
  echo $e-getMessage();//this getMessage throws an exception if any

 }
 ?



Does the code work OUTSIDE of Apache?

php-5.3 your-script.php

Have you considered chroot?

http://www.openbsd.org/faq/faq10.html#httpdchroot

HTH



Re: PHP SQLite connection in OpenBSD

2011-12-13 Thread Bentley, Dain
Thanks for the help.  I'm getting a different error now:
SQLSTATE[HY000] [1] unable to open database: /path/to/db

Can't seem to find much on this error.  Something from the PHP website about
having to recompile PHP from source but it's an old thread and I'd rather not
use non-packaged third party tools if I can help it.



From: joshua stein [j...@openbsd.org]
Sent: Tuesday, December 13, 2011 6:08 PM
To: Bentley, Dain
Subject: Re: PHP SQLite connection in OpenBSD

 PDO driverssqlite2

 Here is the code I am using to attempt to connect
 ?php
 try {
  // connect to SQLite from PDO database
  $dbh = new PDO(sqlite:/bandwith/stats.db);

you have sqlite2 installed, but the sqlite pdo prefix is for
sqlite 3 databases.

try opening sqlite2:/bandwith/stats.db.



Re: PHP SQLite connection in OpenBSD

2011-12-13 Thread richardtoohey
Quoting Bentley, Dain dbent...@nas.edu:

 Thanks for the help. I'm getting a different error now:
 SQLSTATE[HY000] [1] unable to open database: /path/to/db
 
 Can't seem to find much on this error. Something from the PHP website
 about
 having to recompile PHP from source but it's an old thread and I'd
 rather not
 use non-packaged third party tools if I can help it.
 

And have you tried using the file from sqlite command line to check all OK with
sqlite  the database file?

$ sqlite /path/to/db

 
 
 From: joshua stein [j...@openbsd.org]
 Sent: Tuesday, December 13, 2011 6:08 PM
 To: Bentley, Dain
 Subject: Re: PHP SQLite connection in OpenBSD
 
  PDO drivers sqlite2
 
  Here is the code I am using to attempt to connect
  ?php
  try {
  // connect to SQLite from PDO database
  $dbh = new PDO(sqlite:/bandwith/stats.db);
 
 you have sqlite2 installed, but the sqlite pdo prefix is for
 sqlite 3 databases.
 
 try opening sqlite2:/bandwith/stats.db.



Re: PHP SQLite connection in OpenBSD

2011-12-13 Thread richardtoohey
Quoting richardtoo...@paradise.net.nz:

 Quoting Bentley, Dain dbent...@nas.edu:
 
  Thanks for the help. I'm getting a different error now:
  SQLSTATE[HY000] [1] unable to open database: /path/to/db
  
  Can't seem to find much on this error. Something from the PHP website
  about
  having to recompile PHP from source but it's an old thread and I'd
  rather not
  use non-packaged third party tools if I can help it.
  
 
 And have you tried using the file from sqlite command line to check all
 OK with
 sqlite  the database file?
 
 $ sqlite /path/to/db
 

Got to be something you've done - works fine here for me ...

Built a 4.9 i386 box, installed same packages as you ...

No need to build anything or configure anything.

# cd /tmp/ 
# sqlite test.db
SQLite version 2.8.17
Enter .help for instructions
sqlite CREATE TABLE apple (apple_id INTEGER);
sqlite INSERT INTO apple (apple_id) VALUES(44);
sqlite SELECT * FROM apple;
44
sqlite 

# php test.php  
Array
(
[apple_id] = 44
[0] = 44
)

# cat /tmp/test.php
?php
try {
$dbh=new PDO(sqlite2:/tmp/test.db);
} catch (PDOException $e) {
print_r($e);
}
$res=$dbh-query(SELECT * FROM apple);
foreach ($res as $r) {
print_r($r);
}
?

HTH.

  
  
  From: joshua stein [j...@openbsd.org]
  Sent: Tuesday, December 13, 2011 6:08 PM
  To: Bentley, Dain
  Subject: Re: PHP SQLite connection in OpenBSD
  
   PDO drivers sqlite2
  
   Here is the code I am using to attempt to connect
   ?php
   try {
   // connect to SQLite from PDO database
   $dbh = new PDO(sqlite:/bandwith/stats.db);
  
  you have sqlite2 installed, but the sqlite pdo prefix is for
  sqlite 3 databases.
  
  try opening sqlite2:/bandwith/stats.db.



Re: PHP SQLite connection in OpenBSD

2011-12-13 Thread Bentley, Dain
Thanks, that helped.  I got it to connect.

From: richardtoo...@paradise.net.nz [richardtoo...@paradise.net.nz]
Sent: Tuesday, December 13, 2011 7:50 PM
To: Bentley, Dain
Cc: misc@openbsd.org; richardtoo...@paradise.net.nz
Subject: Re: PHP SQLite connection in OpenBSD

Quoting richardtoo...@paradise.net.nz:

 Quoting Bentley, Dain dbent...@nas.edu:

  Thanks for the help. I'm getting a different error now:
  SQLSTATE[HY000] [1] unable to open database: /path/to/db
 
  Can't seem to find much on this error. Something from the PHP website
  about
  having to recompile PHP from source but it's an old thread and I'd
  rather not
  use non-packaged third party tools if I can help it.
 

 And have you tried using the file from sqlite command line to check all
 OK with
 sqlite  the database file?

 $ sqlite /path/to/db


Got to be something you've done - works fine here for me ...

Built a 4.9 i386 box, installed same packages as you ...

No need to build anything or configure anything.

# cd /tmp/
# sqlite test.db
SQLite version 2.8.17
Enter .help for instructions
sqlite CREATE TABLE apple (apple_id INTEGER);
sqlite INSERT INTO apple (apple_id) VALUES(44);
sqlite SELECT * FROM apple;
44
sqlite

# php test.php
Array
(
[apple_id] = 44
[0] = 44
)

# cat /tmp/test.php
?php
try {
$dbh=new PDO(sqlite2:/tmp/test.db);
} catch (PDOException $e) {
print_r($e);
}
$res=$dbh-query(SELECT * FROM apple);
foreach ($res as $r) {
print_r($r);
}
?

HTH.

 
  
  From: joshua stein [j...@openbsd.org]
  Sent: Tuesday, December 13, 2011 6:08 PM
  To: Bentley, Dain
  Subject: Re: PHP SQLite connection in OpenBSD
 
   PDO drivers sqlite2
  
   Here is the code I am using to attempt to connect
   ?php
   try {
   // connect to SQLite from PDO database
   $dbh = new PDO(sqlite:/bandwith/stats.db);
 
  you have sqlite2 installed, but the sqlite pdo prefix is for
  sqlite 3 databases.
 
  try opening sqlite2:/bandwith/stats.db.