Connecting to SQLite3 database from PHP 5.25

Connecting to SQLite3 database from PHP 5.25

am 04.12.2007 11:40:48 von John

Hi,

I'm trying to connect to a SQLite3 database for days now but I'm stuck. PHP
returns an error that I made a "call to undefined function sqlite_open(). In
the php.ini the extension=php_pdo.dll and extension=php_sqlite.dll are set.
What am I doing wrong???

Thank you in advance,
John

Re: Connecting to SQLite3 database from PHP 5.25

am 04.12.2007 11:46:23 von luiheidsgoeroe

On Tue, 04 Dec 2007 11:40:48 +0100, John wrote:
> I'm trying to connect to a SQLite3 database for days now but I'm stuck=
.. =

> PHP
> returns an error that I made a "call to undefined function =

> sqlite_open(). In
> the php.ini the extension=3Dphp_pdo.dll and extension=3Dphp_sqlite.dll=
are =

> set.
> What am I doing wrong???

What does phpinfo() tell you about SQLite support?
Also, check the manual for issues regarding installation: =

http://www.php.net/sqlite
-- =

Rik Wasmus

Re: Connecting to SQLite3 database from PHP 5.25

am 04.12.2007 12:10:34 von John

Hi Rik,

Thanks for your speedy reply. phpinfo() doesn't mention SQLite at all. As a
complete newby to php, I read the installation manual and concluded that the
only action to take was to include both extension = lines. Seemingly it not
enough. Ploughed trough the documentation again and again but nothing I
could recognize as an action to take. Therefore I went to this newsgroep for
help...

So if you know how to help me, plese tell :-)

Grtz,
John
"Rik Wasmus" wrote in message
news:op.t2s37lb85bnjuv@metallium.lan...
On Tue, 04 Dec 2007 11:40:48 +0100, John wrote:
> I'm trying to connect to a SQLite3 database for days now but I'm stuck.
> PHP
> returns an error that I made a "call to undefined function sqlite_open().
> In
> the php.ini the extension=php_pdo.dll and extension=php_sqlite.dll are
> set.
> What am I doing wrong???

What does phpinfo() tell you about SQLite support?
Also, check the manual for issues regarding installation:
http://www.php.net/sqlite
--
Rik Wasmus

Re: Connecting to SQLite3 database from PHP 5.25

am 04.12.2007 12:31:33 von oliver.graetz

John schrieb:
> Hi,
>
> I'm trying to connect to a SQLite3 database for days now but I'm stuck. PHP
> returns an error that I made a "call to undefined function sqlite_open(). In
> the php.ini the extension=php_pdo.dll and extension=php_sqlite.dll are set.
> What am I doing wrong???

The extensions you have activated are not related. The php_pdo.dll
contains the core PDO functions and the php_sqlite.dll contains the
"ordinary" sqlite extension. Havind and activating the latter should
yield in sqlite_open() being available. However, perhaps you meant
php_pdo_sqlite.dll and then this would mean you installed the sqlite
module for PDO instead and that you can only use sqlite through PDO.

OLLi

PS: Always using PDO is recommended anyway ;-)

--
"It's gonna hurt like hell, but it's supposed to."
[Doctor, BG 107]

Re: Connecting to SQLite3 database from PHP 5.25

am 04.12.2007 12:45:51 von luiheidsgoeroe

> "Rik Wasmus" wrote in message
> news:op.t2s37lb85bnjuv@metallium.lan...
> On Tue, 04 Dec 2007 11:40:48 +0100, John wrote:
>> I'm trying to connect to a SQLite3 database for days now but I'm stuc=
k.
>> PHP
>> returns an error that I made a "call to undefined function =

>> sqlite_open().
>> In
>> the php.ini the extension=3Dphp_pdo.dll and extension=3Dphp_sqlite.dl=
l are
>> set.
>> What am I doing wrong???
>
> What does phpinfo() tell you about SQLite support?
> Also, check the manual for issues regarding installation:
> http://www.php.net/sqlite

Please use bottomposting, and quote correctly. MSOE has some quircks, so=
=

if you haven't allready, please install OEQuotefix.

On Tue, 04 Dec 2007 12:10:34 +0100, John "> wrote:
> Thanks for your speedy reply. phpinfo() doesn't mention SQLite at all.=


What file does phpinfo() tell you is used for the settings (Configuratio=
n =

File (php.ini) Path)? Especially on Windows, the file you edit might no=
t =

be the file it uses...

> As a
> complete newby to php, I read the installation manual and concluded th=
at =

> the
> only action to take was to include both extension =3D lines.

If on Windows, with a PHP version >=3D 5.1, that would be correct.
-- =

Rik Wasmus

Re: Connecting to SQLite3 database from PHP 5.25

am 04.12.2007 12:50:04 von luiheidsgoeroe

On Tue, 04 Dec 2007 12:31:33 +0100, Oliver Grätz
wrote:

> John schrieb:
>> Hi,
>>
>> I'm trying to connect to a SQLite3 database for days now but I'm stuck.
>> PHP
>> returns an error that I made a "call to undefined function
>> sqlite_open(). In
>> the php.ini the extension=php_pdo.dll and extension=php_sqlite.dll are
>> set.
>> What am I doing wrong???
>
> The extensions you have activated are not related. The php_pdo.dll
> contains the core PDO functions and the php_sqlite.dll contains the
> "ordinary" sqlite extension. Havind and activating the latter should
> yield in sqlite_open() being available. However, perhaps you meant
> php_pdo_sqlite.dll and then this would mean you installed the sqlite
> module for PDO instead and that you can only use sqlite through PDO.

Well, a quick look at the manual:
"In PHP 5, the SQLite extension and the engine itself are bundled and
compiled by default. However, since PHP 5.1.0 you need to manually
activate the extension in php.ini (because it is now bundled as shared).
Moreover, since PHP 5.1.0 SQLite depends on PDO it must be enabled too, by
adding the following lines to php.ini (in order):
extension=php_pdo.dll
extension=php_sqlite.dll"

... so the OP is correct.


--
Rik Wasmus

Re: Connecting to SQLite3 database from PHP 5.25

am 04.12.2007 15:02:36 von colin.mckinnon

On 4 Dec, 11:50, "Rik Wasmus" wrote:
> On Tue, 04 Dec 2007 12:31:33 +0100, Oliver Grätz
> wrote:
>
>
>
> > John schrieb:
> >> Hi,
>
> >> I'm trying to connect to a SQLite3 database for days now but I'm stuck.=

> >> PHP
> >> returns an error that I made a "call to undefined function
> >> sqlite_open(). In
> >> the php.ini the extension=3Dphp_pdo.dll and extension=3Dphp_sqlite.dll =
are
> >> set.
> >> What am I doing wrong???
>
> > The extensions you have activated are not related. The php_pdo.dll
> > contains the core PDO functions and the php_sqlite.dll contains the
> > "ordinary" sqlite extension. Havind and activating the latter should
> > yield in sqlite_open() being available. However, perhaps you meant
> > php_pdo_sqlite.dll and then this would mean you installed the sqlite
> > module for PDO instead and that you can only use sqlite through PDO.
>
> Well, a quick look at the manual:
> "In PHP 5, the SQLite extension and the engine itself are bundled and
> compiled by default. However, since PHP 5.1.0 you need to manually
> activate the extension in php.ini (because it is now bundled as shared).
> Moreover, since PHP 5.1.0 SQLite depends on PDO it must be enabled too, by=

> adding the following lines to php.ini (in order):
> extension=3Dphp_pdo.dll
> extension=3Dphp_sqlite.dll"
>
> .. so the OP is correct.
>
> --
> Rik Wasmus

BTW phpinfo() will also tell you where it is trying to load the
php.ini file *from* maybe you updated the wrong one?

C.

Re: Connecting to SQLite3 database from PHP 5.25

am 05.12.2007 13:31:49 von John

Hi Rik,

Finally I succeeded in connecting to the database. As you mentioned I edited
the PHP.ini which was not read. Copying the file to the windows directory
made the connection work. Now I can focus on getting the php generator to
deliver some working code. Thank you very much for helping me out. I owe you
one!

Grtz,
John

Re: Connecting to SQLite3 database from PHP 5.25

am 05.12.2007 16:58:20 von AnrDaemon

Greetings, C. (http://symcbean.blogspot.com/).
In reply to Your message dated Tuesday, December 4, 2007, 17:02:36,

> BTW phpinfo() will also tell you where it is trying to load the
> php.ini file *from* maybe you updated the wrong one?

Sad thing is that I have phpinfo() pointing to %WinDir%\php.ini while settings
actually readed from /usr/php-5.2.2/php-apache2_2_filter.ini (And there is no
%WinDir%\php.ini at all too)

Dunno if it is fixed in 5.2.5 or not.


--
Sincerely Yours, AnrDaemon

Re: Connecting to SQLite3 database from PHP 5.25

am 05.12.2007 17:01:16 von AnrDaemon

Greetings, John.
In reply to Your message dated Wednesday, December 5, 2007, 15:31:49,

> Finally I succeeded in connecting to the database. As you mentioned I edited
> the PHP.ini which was not read. Copying the file to the windows directory
> made the connection work.

You did that the worst available way.
What You should do actually, is to point PHP to right INI location.
There's some ways to do that depends on what scripting engine You using.
In Apache (both handler and filter SAPI) -


php_admin_value extension_dir "C:/usr/sbin/php-5.2.2-Win32/ext"
PHPIniDir "C:/usr/sbin/php-5.2.2-Win32"



--
Sincerely Yours, AnrDaemon

Re: Connecting to SQLite3 database from PHP 5.25

am 07.12.2007 07:39:11 von John

"AnrDaemon" wrote in message
news:07765532.20071205190116@freemail.ru...

Hi AnrDaemon,

> You did that the worst available way.
> What You should do actually, is to point PHP to right INI location.
> There's some ways to do that depends on what scripting engine You using.
> In Apache (both handler and filter SAPI) -

>
> php_admin_value extension_dir "C:/usr/sbin/php-5.2.2-Win32/ext"
> PHPIniDir "C:/usr/sbin/php-5.2.2-Win32"
>


Let me try to find the right line to point PHP to the right place. In the
meantime it still is very problematic to get something out of the database
on the webbrowsers screen. PHP let's me connect to the database but after
that it is a no go. It return an errormessage that the database is encrypted
or not a database at all. Seems an issue between the latetst SQLite version
and PHP. I'm at the brink of giving up and convert the database to a mysql
environment. Very sad...

Thank you very much for your direction in the PHP.ini issue.

Grtz,
John

Re: Connecting to SQLite3 database from PHP 5.25

am 07.12.2007 11:25:17 von kim

On Dec 4, 11:40 am, "John" wrote:
> Hi,
>
> I'm trying to connect to a SQLite3 database for days now but I'm stuck. PHP
> returns an error that I made a "call to undefined function sqlite_open(). In
> the php.ini the extension=php_pdo.dll and extension=php_sqlite.dll are set.
> What am I doing wrong???
>
> Thank you in advance,
> John

SQLite3 is only supported with PDO in PHP 5.
As you have found out, 2 lines must be added to the php.ini file:
extension=php_pdo.dll
extension=php_sqlite.dll

When you want to connect to a SQLite3 Database you do this:
$dbh = new PDO('sqlite:');
$results = $dbh->Query("");
while ($row = $results->Fetch(PDO::FETCH_ASSOC)) {
// stuff
}

See http://www.php.net/manual/en/ref.pdo.php for more details.

Re: Connecting to SQLite3 database from PHP 5.25

am 07.12.2007 16:23:48 von oliver.graetz

John schrieb:
> Let me try to find the right line to point PHP to the right place. In the
> meantime it still is very problematic to get something out of the database
> on the webbrowsers screen. PHP let's me connect to the database but after
> that it is a no go. It return an errormessage that the database is encrypted
> or not a database at all. Seems an issue between the latetst SQLite version
> and PHP.

To check the type:

public static function checkFileType($path)
{
if (!file_exists($path)) return 'not found';

$f=fopen($path,'r');
if (!$f)
{
return 'locked';
}

$test=fread($f,44);
fclose($f);

if(strstr($test,'** This file contains an SQLite 2.1 database'))
return 'sqlite2';
elseif(strstr($test,'SQLite format 3'))
return 'sqlite3';
else
return 'unknown';
}

Now you can use a switch() to use the right connection type. I use two
classes for the different connection types. The one for SQLite2 uses

$this->db = new SQLiteDatabase($dbFile,0666,$this->err);

The one for SQLite3 uses:

$this->db = new PDO('sqlite:'.$dbFile);

This objects are encapsulated in two connection classes that both
provide a compatible API to use one version of SQLite or the other.

But: This code is pretty old, in modern PHP you should be able to use
PDO for both versions of SQLite and to use "sqlite:" for version3 and
"sqlite2:" for version 2. This removes the need for an abstraction layer
for the two versions because now the API is PDO for both versions.

OLLi


--
Tom: "You are aware of our project?"
Vaughn: "We're aware you pay good money."
Tom: "We require quite a commitment."
Vaughn: "We require quite a payment."
[Alias 405]