Running SQLite 3 in MicroApache - php

I'm running MicroApache (http://microapache.amadis.sytes.net) on Windows XP and would like to use SQLite 3 databases.
The PHP version is 5.2.9-2.
My MicroApache version has SQLite 2 support through 2 lines in the php.ini:
extension=php_pdo.dll
extension=php_sqlite.dll
I test whether the extension works in 3 ways:
1. phpinfo()
2. extension_loaded() and get_loaded_extensions()
3. using sample code that var_dump()s the constant SQLITE3_NUM (should be the integer 2)
and tries to create a database (error: class 'SQLite3' does not exist)
Things I have tried (if I can remember them all):
1. copied php_sqlite3.dll from a full installation of PHP and added "extension=php_sqlite3.dll" to php.ini
-> error "Procedure entry point gc_remove_zval_from_buffer was not found in php5ts.dll"
2. compressed the DLL with UPX (like the other DLLs of MicroApache seem to be)
-> does not display an error on start, nor in the log file, but does not work
3. tried various things with php.ini
- created a section "[sqlite3]"
- prefixed "sqlite3." to "extension_dir=." and "extension=php_sqlite3.dll"
- ...
4. tried to use PDO, it says it 'could not find driver'
Who can help me get SQLite 3 to work?

The problem of connecting to SQLite 3 DBs and similar problems are covered and discussed on a forum post entitled, "Connecting to SQLite3 database from PHP 5.25" This may answer some of your queries.
The latest build of SQLite is compiled-in to PHP5 and is enabled via PDO.
It shows in PHPINFO.PHP as
2.0-dev "$Id: sqlite.c,v 1.166.2.13.2.12 2008/12/31 11:17:44 sebastian Exp $"
Sounds more like a problem with the test code. Have you cross-checked by running on an SQLite system with standard Apache and the same version of PHP? What are the result from phpinfo(), etc?
The recent MicroApache distros come with a PHP/SQLite guestbook as a demo/test. Does this not work?
Come to think of it you may not have spotted that there's an SQLite distro. Why not revisit the site and check the other versions out (just unzip and run).
MicroApache 2.0.63+PHP 4.4.9+SQLite:
As always I point out that MicroApache isn't intended to be used on a public-facing webserver without paying specific attention to the security config. It was developed merely as a way of sharing information locally via floppy or USB stick. It's easy enough to harden though.
I'm sure you are aware that the SQLite developer renamed a number of the functions with the advent of SQLite3 including the open function - (See here: An Introduction To The SQLite C/C++ Interface ) - I'm not sure how this has been handled by the PHP developers including this codebase into PHP. The suggestion from the page linked above is that you can open PHp3 DBs "as is" with the right PHP code.
Mixing DLLs from different distros of PHP isn't recommended. I don't recommend any other use of the MicroApache distro other than "as is". Adding or mixing DLLs from differing versions of PHP etc. to MicroApache may introduce serious bugs or security problems.
There has been little or no interest in SQLite with MicroApache to date so I've really not dug too deeply into it other than to check the functionality works.
I don't rely too heavily on what's reported by phpinfo().
Perhaps you can update with your info to confirm if the version being reported is accurate.
Update
I've had time to research a little more and a discussion on php5-sqlite3 at the Mac OS Forge mailing list answers your problem.
The PHP implementation is partial and not well documented. Some SQLite3 procedural function calls are only exposed by an object based hierarchy. The procedural API only offers the ability to open SQLite 2 DBs so you're stuck with using objects by the looks of it.
There is also a PECL extension, php-sqlite3, which was
developed during 2008, currently at
version 0.6. This is what the
php5-sqlite3 port installs. But it
does not provide the sqlite3_open
function you are seeking. Rather, it
gives you an object-oriented interface
based around three classes: SQLite3,
SQLite3Stmt and SQLite3Result. It is
described here, rather incompletely,
notably the installation
instructions are totally missing:
MicroApache 2.0.63+PHP 5.2.9+SQLite
MicroApache 1.3.41+PHP 4.4.9+SQLite
MicroApache 1.3.41+PHP 4.4.9+SQLite
MicroApache 1.3.41+PHP 4.4.9+SQLite+GD2
Hopefully you can play with these distros and solve your problems.
There is an SQLite3.DLL included with the distro as a courtesy which can be accessed directly from VB5/6 or any compatible language which can call the DLL.
Using SQLITE 3 from Visual BASIC 5
This was a separate project I had a look at some while ago. This was produced in MSVC by editing the original source. This DLL isn't compatible with PHP/PDO but could be used via a CGI interface. Alternately the original SQLite 3 DLL could be obtained and used via Delphi etc.

Please be aware that I do have the distro with SQLite support. However it only has support for version 2, not 3.
My MicroApache version has SQLite 2 support [...]
I would like to use SQLite 3 because it is faster, I could interact with the databases I created for a project in Delphi and I could access the newly created databases with the Firefox extension SQLite Manager.

I've tinkered with this problem some more, but could still not create/access a SQLite 3 database.
Interestingly, the link you provided in Part 1 mentions a class "SQLiteDatabase" which is not found in the PHP documentation and is not part of the SQLite3 extension (which is object oriented - as mentioned in your last post, Mad Max).
"SQLiteDatabase" creates a database, but when you open it, you can see that it is in version 2.1.
Thanks for the help.
EDIT:
PDO works only when I use the DSN prefix "sqlite2" which is not very surprising, since phpinfo() only lists the driver "sqlite2" under the section "PDO".

Related

PHP 7.4 with Firebird Interbase [duplicate]

I'm dealing with a legacy firebird database and can't seem to get it to work with PHP7.4.
The interbase extension isn't available anymore in PHP7.4, I can only install PDO_FIREBIRD.
There are also no releases on PECL.
https://pecl.php.net/package/interbase
Any hints how to make it work with 7.4?
Recent versions of PHP indeed no longer ship with the interbase package. Instead you can use the Firebird PHP driver, which is a fork and continued development of the interbase package.
Well, I faced some caveats while dealing with legacy Firebird data structures.
To put it simply, I had to address two broad issues:
1 - Match client libraries with dataset On-disk Structure (ODS)
Each Firebird version supports a limited range of On-Disk Structures (ODSs). The following link has a pretty nice reference on this topic:
https://ib-aid.com/en/articles/all-firebird-and-interbase-on-disk-structure-ods-versions
ADODB and PHP PDO are abstraction layers to client libraries in the host system. And PHP 7.4 supports only FB 3.0 and later clients. So, it is necessary to match the abstraction layer with the client library available.
For datasets up to FB 2.5:
disk structure should be up to ODS 11;
client version should be up to FB 2.5.9 (recommended);
PHP engine should be up to 7.3 (7.1 already has issues);
legacy functions ibase_ and fbird_ should work fine;
ADODB, PHP PDO, etc. should not work.
For datasets starting from FB 3.0:
disk structure should be ODS 12 or higher;
client version should be FB 3.0 or higher;
PHP engine should be 7.4 or higher;
legacy functions ibase_ and fbird_ should not work;
ADODB, PDO etc. should work fine.
2 - Match client and server platforms and params
For any client and server combination:
the client and the server should share the same platform, 32 or 64 bits;
the connection should use SQL dialect 1 or 3, depending on legacy dataset usage;
the character encoding should be WIN-1251 (legacy) or UTF-8 (new default).
Opinion
In my experience, it is difficult to "force" legacy FB connections into an up-to-date PHP engine. I suppose it is more challenging with Linux systems because libgcc has different entry points from versions 5 to 6 (I guess...), and musl just ain't supported.
Things are more flexible in Windows since fbclient.dll is the only client library needed for the connection, and it depends on Win32 libraries that have maintained the same entry points over the years.
I'd recommend upgrading the dataset to Firebird 4 and using updated extensions and clients. However, if this is not an option, downgrading should be streamlined from the host OS, through the PHP engine, until the FB client.
Unfortunately, I believe "this is the way."
All the best.
Recently I have problems connecting firebird with php. I went through many questions until I discovered that there has to be 3 dll's inside the apache bin folder. gds32.dll
msvcr71.dll
fbclient.dll.
Without these dll's it doesn't work, for some unknown reason the new version of xampp came missing.

PHP7.4 and firebird/interbase: ibase_connect(), ibase_query() Call to undefined function

I'm dealing with a legacy firebird database and can't seem to get it to work with PHP7.4.
The interbase extension isn't available anymore in PHP7.4, I can only install PDO_FIREBIRD.
There are also no releases on PECL.
https://pecl.php.net/package/interbase
Any hints how to make it work with 7.4?
Recent versions of PHP indeed no longer ship with the interbase package. Instead you can use the Firebird PHP driver, which is a fork and continued development of the interbase package.
Well, I faced some caveats while dealing with legacy Firebird data structures.
To put it simply, I had to address two broad issues:
1 - Match client libraries with dataset On-disk Structure (ODS)
Each Firebird version supports a limited range of On-Disk Structures (ODSs). The following link has a pretty nice reference on this topic:
https://ib-aid.com/en/articles/all-firebird-and-interbase-on-disk-structure-ods-versions
ADODB and PHP PDO are abstraction layers to client libraries in the host system. And PHP 7.4 supports only FB 3.0 and later clients. So, it is necessary to match the abstraction layer with the client library available.
For datasets up to FB 2.5:
disk structure should be up to ODS 11;
client version should be up to FB 2.5.9 (recommended);
PHP engine should be up to 7.3 (7.1 already has issues);
legacy functions ibase_ and fbird_ should work fine;
ADODB, PHP PDO, etc. should not work.
For datasets starting from FB 3.0:
disk structure should be ODS 12 or higher;
client version should be FB 3.0 or higher;
PHP engine should be 7.4 or higher;
legacy functions ibase_ and fbird_ should not work;
ADODB, PDO etc. should work fine.
2 - Match client and server platforms and params
For any client and server combination:
the client and the server should share the same platform, 32 or 64 bits;
the connection should use SQL dialect 1 or 3, depending on legacy dataset usage;
the character encoding should be WIN-1251 (legacy) or UTF-8 (new default).
Opinion
In my experience, it is difficult to "force" legacy FB connections into an up-to-date PHP engine. I suppose it is more challenging with Linux systems because libgcc has different entry points from versions 5 to 6 (I guess...), and musl just ain't supported.
Things are more flexible in Windows since fbclient.dll is the only client library needed for the connection, and it depends on Win32 libraries that have maintained the same entry points over the years.
I'd recommend upgrading the dataset to Firebird 4 and using updated extensions and clients. However, if this is not an option, downgrading should be streamlined from the host OS, through the PHP engine, until the FB client.
Unfortunately, I believe "this is the way."
All the best.
Recently I have problems connecting firebird with php. I went through many questions until I discovered that there has to be 3 dll's inside the apache bin folder. gds32.dll
msvcr71.dll
fbclient.dll.
Without these dll's it doesn't work, for some unknown reason the new version of xampp came missing.

php pdo_informix on windows 7 64 bit and wamp 64 bit

I try to install pdo_informix in WAMP 64 bit on windows 7 64 bit, but I found problem because pdo_informix.dll is version 32 bit. I try to search for pdo_informix.dll, but I can't found it. How to solve this problem?
Thank you for help.
It looks as though you may have to download the source for PDO Informix and compile it; that is always an available option for open source (get the code and compile it) but it presumes you have the facilities needed to compile code.
A Google search with the terms 'pdo informix 64-bit windows' picks up this question, amongst others, and also points to the PDO Informix manual which includes links to 'how to compile PDO extensions' etc.
Google also lists a IIS forum posting on the subject which says (lightly edited):
As an alternative, there is a simpler option; however, it may not be ideal depending on your requirements. There is a tool called OpenAdmin Tool for Informix. This is a PHP-based tool for administrative tasks on an Informix database. The tool is a ready-built Apache webserver with PHP set up which uses the Informix pdo driver (it is actually embedded), however, the rest of it is the same, you could copy any extra extensions/modules from your existing setup over to the OpenAdmin PHP directory and enable them in the OpenAdmin php.ini file.Then put whatever ever resides in your existing htdocs folder into the OpenAdmin htdocs folder.
It lists links to the IBM site for OAT (OpenAdmin Tool), but the links embed the date 2006-01-26, so they're probably not current and likely not directly available. The latest information is available from the OpenAdmin Tool website.
OAT does not seem to be distributed for 64-bit Windows specifically.
I also have the same problem right now.
The OpenAdmin Tool website says that the Informix Client SDK which is available on the IBM website includes a ready-to-use OpenAdmin Tool including Apache Webserver, PHP and the pdo_informix extension.
However, the current SDK 4.10 is NOT shipped with the OpenAdmin Tool.
So you have to set up your own environment with Apache and PHP and the community edition of OpenAdmin Tool. I tried Apache 2.4 for x_86 and x_64 Systems (Windows) and all available Versions of PHP (5.4, 5.5, 5.6).
You can download the pdo_informix extension for PHP 5.4 here:
https://pecl.php.net/package/PDO_INFORMIX/1.3.1/windows
And there was a guy who compiled it for PHP 5.5:
https://github.com/maryo/php-5.5-windows-extensions/tree/master/php_pdo_informix-1.3.1-5.5-vc11-x86
There is also a hint that it is very important to set the INFORMIXDIR environment variable correctly. I tried several possibilities such as C:\Program Files\IBM Informix Software Bundle\ or with a trailing \bin but it did not help.
Unfortunately, nothing worked for me. The pdo_informix extension did not load. Hopefully I can help someone with my explanations to get the OAT up and running.

How easy is it to use PHP on an MS Server with MS SQL?

I generally use linux servers and program in PHP (plus other associated technologies) with mysql databases. A client has existing ASP sites using MSSQL databases on a Windows server and wants some new sites created on their server using their MSSQL database as the main data source. I have used ASP in the past but much prefer PHP so would rather use this.
I just wanted to confirm that i'm right in saying as long as the server has PHP installed (which it does) then there's no reason I can't create a PHP site on the Windows server and just use different connectors to connect to the MSSQL db (rather than what i would usually use for connecting to a MYSQL db). Presumably (other than the different connect/query code) this would work in pretty much the same way as with a linux setup with mysql and i could then code the site in PHP but use their existing datasource?
I would be extremely grateful if anyone could confirm i'm right in saying this and if there's any other issues that might cause any problems?
Thanks so much for your help as ever,
Dave
You can enable MSSQL support in PHP on Windows. The default Windows PHP install has the php_mssql.dll extension commented out in the php.ini file. Uncomment that line, restart Apache, and it should work.
There is a supporting DLL called ntwdblib.dll that you may need to find a replacement for, as the version included with PHP may be outdated and won't work with newer versions of SQL Server. (I had this problem when setting it up.)
There are two different libraries to connect to SQL Server from PHP:
The legacy mssql extension, which has been discontinued on Windows
Microsoft's sqlsrv extension, which only works on Windows
I've basically worked with the second one and I can say it's a very interesting product. It's robust, it has a very nice interface and it's totally up-to-date. But what I like most is that it has very nice features. E.g.:
It can return dates as PHP DateTime objects
It provides a PDO driver
The only drawback of using SQL Server is that there isn't an easy way to write a cross-platform app but I understand it isn't problem in your case.
Yes, it is rather straight forweard.
You need to have the mssql library activated in php.ini. Which can be troublesom.
MSSSQL docmentation

Pure PHP implementation of SQLite?

Is there a pure PHP implementation of SQLite that will run on PHP 5.1.6? I am working on an application that would benefit from being able to store data in a relational database, but the server that it has to run on is stuck with PHP 5.1.6 and has been configured "'--without-sqlite"
I have no control over this server; cannot recompile, upgrade or otherwise modify PHP aside from using .htaccess files. Hosting externally is also not an option, unfortunately. MySQL may be possible but would be a nightmare trying to get their IT to create a database for me. (It took them 6 weeks to get .htaccess files enabled because of red tape and other things)
Am I out of luck? My fall back is to write everything to flat files but I really would rather not do that.
EDIT: Fixed typo. PHP does not have the SQLite extension and was configured "'--without-sqlite" according to the output of phpinfo()
Actually, you could easily download and install sqlite in your userspace, whether on windows or on a linux remote shell doesn t usually matter unless your host is unusually restrictive, if that is the case you should change service provider.
Once sqlite is installed, you can one of the available pear extensions or pecl extension to allow easy access through php.
Tutorial and code examples for the pear solution here.

Categories