Bookmarks

Yahoo Gmail Google Facebook Delicious Twitter Reddit Stumpleupon Myspace Digg

Search queries



Links

Issociate
Impressum

#1: Connecting to SQLite3 database from PHP 5.25

Posted on 2007-12-04 11:40:48 by 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

Report this message

Mr Ad

Google

#2: Re: Connecting to SQLite3 database from PHP 5.25

Posted on 2007-12-04 11:46:23 by luiheidsgoeroe

On Tue, 04 Dec 2007 11:40:48 +0100, John <johnk@faramir.nl> 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

Report this message

#3: Re: Connecting to SQLite3 database from PHP 5.25

Posted on 2007-12-04 12:10:34 by 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" <luiheidsgoeroe@hotmail.com> wrote in message
news:op.t2s37lb85bnjuv@metallium.lan...
On Tue, 04 Dec 2007 11:40:48 +0100, John <johnk@faramir.nl> 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

Report this message

#4: Re: Connecting to SQLite3 database from PHP 5.25

Posted on 2007-12-04 12:31:33 by 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]

Report this message

#5: Re: Connecting to SQLite3 database from PHP 5.25

Posted on 2007-12-04 12:45:51 by luiheidsgoeroe

> "Rik Wasmus" <luiheidsgoeroe@hotmail.com> wrote in message
> news:op.t2s37lb85bnjuv@metallium.lan...
> On Tue, 04 Dec 2007 11:40:48 +0100, John <johnk@faramir.nl> 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 <do not use <"this>"> 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

Report this message

#6: Re: Connecting to SQLite3 database from PHP 5.25

Posted on 2007-12-04 12:50:04 by luiheidsgoeroe

On Tue, 04 Dec 2007 12:31:33 +0100, Oliver Grätz <oliver.graetz@gmx.de>
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

Report this message

#7: Re: Connecting to SQLite3 database from PHP 5.25

Posted on 2007-12-04 15:02:36 by colin.mckinnon

On 4 Dec, 11:50, "Rik Wasmus" <luiheidsgoe...@hotmail.com> wrote:
> On Tue, 04 Dec 2007 12:31:33 +0100, Oliver Gr=E4tz <oliver.gra...@gmx.de>
> 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.

Report this message

#8: Re: Connecting to SQLite3 database from PHP 5.25

Posted on 2007-12-05 13:31:49 by 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

Report this message

#9: Re: Connecting to SQLite3 database from PHP 5.25

Posted on 2007-12-05 16:58:20 by 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 <anrdaemon@freemail.ru>

Report this message

#10: Re: Connecting to SQLite3 database from PHP 5.25

Posted on 2007-12-05 17:01:16 by 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) -

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


--
Sincerely Yours, AnrDaemon <anrdaemon@freemail.ru>

Report this message

#11: Re: Connecting to SQLite3 database from PHP 5.25

Posted on 2007-12-07 07:39:11 by John

"AnrDaemon" <anrdaemon@freemail.ru> 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) -

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

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

Report this message

#12: Re: Connecting to SQLite3 database from PHP 5.25

Posted on 2007-12-07 11:25:17 by kim

On Dec 4, 11:40 am, "John" <jo...@faramir.nl> 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:<path_to_DBfile>');
$results = $dbh->Query("<your_query>");
while ($row = $results->Fetch(PDO::FETCH_ASSOC)) {
// stuff
}

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

Report this message

#13: Re: Connecting to SQLite3 database from PHP 5.25

Posted on 2007-12-07 16:23:48 by 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]

Report this message