473,800 Members | 3,089 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_p do.dll and extension=php_s qlite.dll are set.
What am I doing wrong???

Thank you in advance,
John
Dec 4 '07 #1
12 17270
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_p do.dll and extension=php_s qlite.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_p do.dll and extension=php_s qlite.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.comwro te in message
news:op******** *******@metalli um.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_p do.dll and extension=php_s qlite.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.in i while settings
actually readed from /usr/php-5.2.2/php-apache2_2_filte r.ini (And there is no
%WinDir%\php.in i at all too)

Dunno if it is fixed in 5.2.5 or not.
--
Sincerely Yours, AnrDaemon <an*******@free mail.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*******@free mail.ru>

Dec 5 '07 #7
"AnrDaemon" <an*******@free mail.ruwrote in message
news:07******** *************@f reemail.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_p do.dll and extension=php_s qlite.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_p do.dll
extension=php_s qlite.dll

When you want to connect to a SQLite3 Database you do this:
$dbh = new PDO('sqlite:<pa th_to_DBfile>') ;
$results = $dbh->Query("<your_q uery>");
while ($row = $results->Fetch(PDO::FET CH_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,$t his->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

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

Similar topics

2
2200
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 via the sqlite3 cli so I can dynamically change were the output goes. Ta
66
7092
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 has been upgraded, I can go ahead and install Python 2.5. So I open the manual to Section 13.13 where I find the first example of how to use Sqlite3:
2
4954
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 = sqlite3.connect(':memory:') conn.execute("create table foo (a int,b int)") conn.execute('create view bar as select * from foo')
13
1837
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
2278
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 created in a thread can only be used in that same thread.The object was created in thread id 240 and this
0
4109
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 calls. The relevant source code is here if you're interested: http://svn.python.org/projects/python/trunk/Modules/_sqlite/cursor.c
1
3108
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 controlled by changing the connection's text_factory. I have a database that stores strings in 8-bit ISO-8859. So, I set the text_factory to do no conversion. In my database I use user defined functions. I noticed that even when I set...
0
1765
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 than using the sqlite3 CLI and the .import command (reading the same data from a disk file, even.) i find this surprising, executemany() i assume is using a prepared statement and this is exactly what the .import command does (based on my quick...
15
14793
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 directory". So, I assume that the absence of the "sqlite3.h" is the origin of the problem. I found on the web, that this file should be either in "/usr/local/ include" or in "/usr/local/lib". I check this directories and I really
0
9689
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9550
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10495
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10269
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9085
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7573
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6811
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5597
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2942
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.