Boolean support in PHP

46 views
Skip to first unread message

Emil Totev

unread,
Jul 6, 2020, 7:45:48 AM7/6/20
to Firebird-PHP
Has anyone tried to patch php_interbase to recognize the boolean data type? Is it something complicated, or it could be done easily?

Regards
Emil

martin.koeditz

unread,
Jul 13, 2020, 10:26:32 AM7/13/20
to Firebird-PHP
Hi,

what do you mean by that? I didn't had any problems with boolean fields yet. But if there is a bug we can surely repair that.

Regards
Martin

Emil Totev

unread,
Jul 13, 2020, 11:13:23 AM7/13/20
to Firebird-PHP
I mean a field declared as SQL type BOOLEAN (true/false), available since FB 3.0. The driver seems to not recognize this data type.
Simplest test case, against any Firebird 3+ server (note the missing quotes in the second query):
<?php
ibase_connect('localhost:employee','sysdba','masterkey');
$res = ibase_query("select 1, 'true', 'false' from rdb\$database");
$rec = ibase_fetch_assoc($res);
var_dump($rec);

$res = ibase_query("select 1, true, 'false' from rdb\$database");
$rec = ibase_fetch_assoc($res);
var_dump($rec);

And the result is

array(3) {
  ["CONSTANT"]=>
  int(1)
  ["CONSTANT_01"]=>
  string(4) "true"
  ["CONSTANT_02"]=>
  string(5) "false"
}
PHP Warning:  ibase_fetch_assoc(): Incorrect values within SQLDA structure empty pointer to data at SQLVAR index 1  in D:\tmp\test.php on line 9

Warning: ibase_fetch_assoc(): Incorrect values within SQLDA structure empty pointer to data at SQLVAR index 1  in D:\tmp\test.php on line 9
bool(false)

PHP 7.3.16 (cli) (built: Mar 17 2020 13:33:00) ( ZTS MSVC15 (Visual C++ 2017) x64 )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.16, Copyright (c) 1998-2018 Zend Technologies

martin.koeditz

unread,
Jul 13, 2020, 11:18:33 AM7/13/20
to Firebird-PHP
Ok, now I see the problem.

I will check how to fix this error. Please be patient. This will take some days.

Regards
Martin

Emil Totev

unread,
Jul 13, 2020, 11:24:32 AM7/13/20
to Firebird-PHP
No hurry :)
This issue has existed ever since Firebird 3 introduced the BOOLEAN data type, and obviously no one cared enough to try to fix it. And now Firebird 4 is about to be released, which also introduces new data types that will be a problem for PHP.

Thanks for looking at this!
Emil

martin.koeditz

unread,
Jul 14, 2020, 3:43:43 AM7/14/20
to Firebird-PHP
Hi Emil,

I created an issue on the tracker. So you can keep track on the development.

Regards
Martin

martin.koeditz

unread,
Aug 3, 2020, 3:00:05 AM8/3/20
to Firebird-PHP
Hi Emil,

I created a new driver version supporting the boolean datatype. What is your environment?

PHP version (7.4, x64 ...)
OS (Linux, Windows ...)

Regards
Martin

Emil Totev

unread,
Aug 3, 2020, 3:14:48 AM8/3/20
to firebi...@googlegroups.com
I am using PHP 7.3, on both Win10 x64 and Linux x64. I don't have development environs on either, so precompiled binaries would be nice.

Best regards
Emil

--
You received this message because you are subscribed to the Google Groups "Firebird-PHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebird-php...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/firebird-php/a87c5347-cd3b-45eb-84da-748d729ebc00o%40googlegroups.com.

martin.koeditz

unread,
Aug 13, 2020, 11:45:23 AM8/13/20
to Firebird-PHP
Hi Emil,

I compiled the PHP 7.4 for Linux and Win. Version for PHP 7.3 is available for Windows. I think the Linux versions will follow tomorrow.

You can download the beta version of the driver at https://firebirdsql.org/en/php-driver/

Please give me some feedback.

Regards
Martin

Emil Totev

unread,
Aug 13, 2020, 1:14:23 PM8/13/20
to firebi...@googlegroups.com
Hi Martin,

I don't have ready test cases for the boolean fields, as I've been avoiding them in my databases up to now, but a very quick test I managed to do shows that boolean values are properly retrieved from the database and there are no errors.

In the coming days I'll try starting to migrate more database fields to real boolean and will let you know how it goes

It will probably be good to post announcements on firebird-php, firebird-general and maybe even on firebird-support so that more people can try the new functionality.

And you could start thinking about the new Firebird4 types - the INT128-based ones and the timestamp with time zone :)

Thanks a lot and best regards
Emil

 



--
You received this message because you are subscribed to a topic in the Google Groups "Firebird-PHP" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/firebird-php/fai_VYLLeI4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to firebird-php...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/firebird-php/e841fac3-e256-4bec-a51c-d833cbfa5d85o%40googlegroups.com.

Paul Vinkenoog

unread,
Aug 13, 2020, 1:28:32 PM8/13/20
to firebi...@googlegroups.com
Hallo Martin,

> I compiled the PHP 7.4 for Linux and Win. Version for PHP 7.3 is available
> for Windows. I think the Linux versions will follow tomorrow.
>
> You can download the beta version of the driver at
> https://firebirdsql.org/en/php-driver/

Thanks, that's very good news! Boolean support in PHP is something that I've
been dearly missing since Firebird 3.0 arrived.

I'll wait for 7.3/Linux and try it out as soon as possible (hopefully within a week).

Cheers,
Paul Vinkenoog

martin.koeditz

unread,
Aug 17, 2020, 12:11:25 PM8/17/20
to Firebird-PHP
Hey Paul,

I uploaded the 7.3 version for Linux too. So please have a try.

Martin

Paul Vinkenoog

unread,
Aug 19, 2020, 1:44:49 PM8/19/20
to firebi...@googlegroups.com
Hi Martin,

> I uploaded the 7.3 version for Linux too. So please have a try.

Thanks, I'll try it out this week.

Cheers,
Paul

Paul Vinkenoog

unread,
Aug 23, 2020, 3:20:21 PM8/23/20
to firebi...@googlegroups.com
Hi Martin,

> I uploaded the 7.3 version for Linux too. So please have a try.

On Win64, both insertions (immediate and prepared) and fetches work fine.

On Linux, insertions work fine (but then, they already did with the extension
from the official package, as I just found out), but fetches fail with:

[23-Aug-2020 21:07:40 Europe/Amsterdam] PHP Warning:
ibase_fetch_object(): Dynamic SQL Error SQL error code = -804
Incorrect values within SQLDA structure in /var/www/html/lib/db_firebird.php
on line 728

Any idea what might be wrong? Of course I first stopped httpd, then replaced
the library, restarted the daemon and ran the test script. When it went wrong
I also took another approach, namely by changing the extension name inside
20-interbase.ini from 'interbase' to 'php-7.3.21-interbase' (I had
php-7.3.21-interbase.so installed in /usr/lib64/php/modules) - but as expected,
this gave the same result.

Cheers,
Paul

martin.koeditz

unread,
Aug 24, 2020, 7:37:32 AM8/24/20
to Firebird-PHP
Hi Paul,

can you provide some short script for the Linux version? Would be very helpful.

Martin

Paul Vinkenoog

unread,
Aug 24, 2020, 8:45:26 PM8/24/20
to firebi...@googlegroups.com
Hi Martin,

> can you provide some short script for the Linux version? Would be very helpful.

Was going to do that, but I thought I'd first try your driver on another system.
And it worked perfectly there.

Now the weird thing is:
- Both are up-to-date CentOS 7 systems
- Both run Apache 2.4.6
- Both run PHP 7.3.21

The only difference I can see so far is that the system where boolean fetches
go wrong runs Firebird 3.0.3 and the other system 3.0.4. But franky, I can't
imagine that *that* is the cause of the problem. Apart from these boolean
fetches, everything runs fine on that server. A PHP 7 application that is used
every day by dozens of people has been running smoothly for 2,5 years now
against that Fb 3.0.3 server.

Unless you have any ideas or suggestions, maybe I'll upgrade the Fb server,
but I don't expect much from that.

Cheers,
Paul

Paul Vinkenoog

unread,
Aug 25, 2020, 9:05:50 PM8/25/20
to firebi...@googlegroups.com
Got it!

There was some creative linking going on in /usr/lib64 on the problematic system:

lrwxrwxrwx 1 root root 32 Mar 3 2018 libfbclient.so -> /opt/firebird/lib/libfbclient.so
lrwxrwxrwx 1 root root 20 Sep 14 2019 libfbclient.so.2 -> libfbclient.so.2.5.9
-rw-r--r-- 1 root root 898608 Aug 22 2019 libfbclient.so.2.5.9
lrwxrwxrwx 1 root root 38 Mar 3 2018 libfbclient.so.3.0.3 -> /opt/firebird/lib/libfbclient.so.3.0.3
...
lrwxrwxrwx 1 root root 32 Mar 3 2018 libgds.so -> /opt/firebird/lib/libfbclient.so
lrwxrwxrwx 1 root root 20 Sep 14 2019 libgds.so.0 -> libfbclient.so.2.5.9

Here, libfbclient.so.2 and libgds.so.0 both linked to libfbclient.so.2.5.9,
whereas libfbclient.so and libgds.so linked to whatever version is installed under /opt/firebird

On the 'good' system. it's:

lrwxrwxrwx. 1 root root 32 Nov 30 2019 libfbclient.so -> /opt/firebird/lib/libfbclient.so
lrwxrwxrwx. 1 root root 11 Nov 30 2019 libfbclient.so.2 -> libgds.so.0
-rw-r--r--. 1 root root 898608 Aug 22 2019 libfbclient.so.2.5.9
lrwxrwxrwx. 1 root root 38 Nov 30 2019 libfbclient.so.3.0.4 -> /opt/firebird/lib/libfbclient.so.3.0.4
...
lrwxrwxrwx. 1 root root 32 Nov 30 2019 libgds.so -> /opt/firebird/lib/libfbclient.so
lrwxrwxrwx. 1 root root 32 Nov 30 2019 libgds.so.0 -> /opt/firebird/lib/libfbclient.so

On this system, libfbclient.so.2 links via libgds.so.0 to /opt/firebird/lib/libfbclient.so
(i.e. current version), as do libfbclient.so and libgds.so. So here, we have nothing to
fear but libfbclient.so.2.5.9 itself.

After correcting the links on the 'bad' system and restarting httpd and firebird,
everything's fine there, php-boolean-wise.

BTW, this means that your driver loads libfbclient.so.2 or libgds.so.0 rather than
libfbclient.so or libgds.so. Is that intentional?

Cheers,
Paul

martin.koeditz

unread,
Aug 26, 2020, 6:19:57 AM8/26/20
to Firebird-PHP
Hi Paul,

thank you for the good news.

Well, usually the system looks in its search path for the libraries. IMHO /usr/lib64 comes (very) first. If there are "strange" linkings we have a problem.
I'm not familiar with the depth of PHP extension programming, but I don't think I can set some special paths for the libraries to use.

Maybe I can check for the loaded library and throw some error message.

Regards,
Martin

Paul Vinkenoog

unread,
Aug 27, 2020, 9:00:41 AM8/27/20
to firebi...@googlegroups.com
Hi Martin,

It's not so much about the search path as the symlinks *in* that search
path, which, on one of my systems, had both libfbclient.so.2 and libgds.so.0
pointing to libfbclient.so.2.5.9.

For libfbclient.so.2 this is logical, for libgds.so.0 it seems questionable
(to me).

But I don't know which link your driver picked up first. To me, the logical
approach would seem to look for Fb3-specific links first, then for the
general libfbclient.so, then libgds.so. But that's only me, I'm not a PHP
driver developer, so I guess you're in a better position to judge that.

Also, it's possible that the config on my problematic system was just
a weird coincidence, caused by order, time and nature of some updates.

So unless you get other similar reports, this is probably not worth
investing more time in. My setup works now and I'm happy :-)

Thanks again for your work on this, I really appreciate it!

Cheers,
Paul Vinkenoog
Reply all
Reply to author
Forward
0 new messages