473,396 Members | 2,070 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Connecting to SQLite3 database from PHP 5.25

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
Dec 4 '07 #1
12 17235
On Tue, 04 Dec 2007 11:40:48 +0100, John <jo***@faramir.nlwrote:
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.dllare
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
Dec 4 '07 #2
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]
Dec 4 '07 #3
"Rik Wasmus" <lu************@hotmail.comwrote in message
news:op***************@metallium.lan...
On Tue, 04 Dec 2007 11:40:48 +0100, John <jo***@faramir.nlwrote:
>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
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 (Configuration
File (php.ini) Path)? Especially on Windows, the file you edit might not
be the file it uses...
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.
If on Windows, with a PHP version >= 5.1, that would be correct.
--
Rik Wasmus
Dec 4 '07 #4
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
Dec 5 '07 #5
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 <an*******@freemail.ru>

Dec 5 '07 #6
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 <an*******@freemail.ru>

Dec 5 '07 #7
"AnrDaemon" <an*******@freemail.ruwrote in message
news:07*********************@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
Dec 7 '07 #8
Kim
On Dec 4, 11:40 am, "John" <jo...@faramir.nlwrote:
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.
Dec 7 '07 #9
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]
Dec 7 '07 #10
Greetings, John.
In reply to Your message dated Friday, December 7, 2007, 09:39:11,
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...
I'd better advice You to move to MySQL (which is multi-user multi-threaded
database) anyway, than start guessing if You have multiple requests to
database at the same time from different sources, or probably some of them may
be writing requests, taking some time and locking database.
--
Sincerely Yours, AnrDaemon <an*******@freemail.ru>

Dec 8 '07 #11
AnrDaemon wrote:
Greetings, John.
In reply to Your message dated Friday, December 7, 2007, 09:39:11,
>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...

I'd better advice You to move to MySQL (which is multi-user multi-threaded
database) anyway, than start guessing if You have multiple requests to
database at the same time from different sources, or probably some of them may
be writing requests, taking some time and locking database.

There is no problem with SQLLite for those who do not need the power of
MySQL (especially if they want to save system resources).

It can be a little difficult to get SQLLite working the first time, but
once you have it working it works well for low volume sites.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Dec 8 '07 #12
Greetings, Jerry Stuckle.
In reply to Your message dated Saturday, December 8, 2007, 07:33:40,
There's an old saying. "It is better to remain silent and be thought an
idiot than to open your mouth and remove all doubt."
It's something you should learn.
Thank You for Your answer, Jerry.
It was as good to understand Your knowledge, as Oliver's answer below.
--
Sincerely Yours, AnrDaemon <an*******@freemail.ru>

Dec 10 '07 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: lolmcbride | last post by:
Hi, is it possible to pass args through the api which are the same as the args you can use on the sqlite3 command line? What I'm talking about is the .mode or .output commands which you can enter...
66
by: mensanator | last post by:
Probably just me. I've only been using Access and SQL Server for 12 years, so I'm sure my opinions don't count for anything. I was, nevertheless, looking forward to Sqlite3. And now that gmpy...
2
by: Josh | last post by:
Hi, I'm running into a problem when trying to create a view in my sqlite database in python. I think its a bug in the sqlite3 api that comes with python 2.5. This works as expected: conn =...
13
by: mark carter | last post by:
I hesitate to ask, but ... I'm using Ubuntu Feisty: * Python 2.5.1 (r251:54863, May 2 2007, 16:56:35) on linux2 * SQLite version 3.3.13 Suppose I run the following program: import sqlite3
2
by: =?ISO-8859-1?Q?S=E9bastien_Ramage?= | last post by:
Hi ! I'm trying to build an client/server app based on Pyro and sqlite3. But I have a problem using sqlite3 on the server I got this error : sqlite3.ProgrammingError: ('SQLite objects...
0
by: David | last post by:
- Are there any peculiarities with using curs.executemany(...) vs. multiple How many times are you calling execute vs a single executemany? The python call overhead will add up for thousands of...
1
by: jeff_d_harper | last post by:
I've run into a problem with text encoding in the Sqlite3 module. I think it may be a bug. By default sqlite3 converts strings in the database from UTF-8 to unicode. This conversion can be...
0
by: Ben Lee | last post by:
hi folks -- a quick python and sqlite3 performance question. i find that inserting a million rows of in-memory data into an in-memory database via a single executemany() is about 30% slower...
15
by: Kurda Yon | last post by:
Hi, I try to "build" and "install" pysqlite? After I type "python setup.py build" I get a lot of error messages? The first error is "src/ connection.h:33:21: error: sqlite3.h: No such file or...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.