From: floriparob at gmail dot com
Operating system: Debian 64bit 3.2.0-2
PHP version: 5.4.4
Package: PostgreSQL related
Bug Type: Bug
Bug description:Null values for insert/update statements
Description:
------------
Actually using PHP 5.4.0.3 but this was not in the drop down list above.
Null is a perfectly valid value for a column. However, PHP fails to submit
the correct values when it builds the SQL query and submits it to the
postmaster.
I don't have this problem with Java and the Postgres jdbc driver.
Consider the following DDL:-
create table table_a (
tablea_id serial not null primary key,
col_a varchar(20),
col_b integer,
col_c boolean default false);
In my class for table_a I have:-
update table_a set col_a = 'this->colA', col_b = this->colB,
col_c = this->colC where tablea_id = $something;
In my action I might set a value -- setcolA('some value');
If this->colB IS NULL, then PHP doesn't detect this fact, generates the
following SQL which fails because of syntax errors.
update table_a set col_a = 'some value', col_b = , col_c = where tablea_id
= 3;
It should generate:-
update table_a set col_a = 'some value', col_b = null, col_c = null where
tablea_id = 3;
The failure to detect boolean's and treat them appropriately is another
pain in the neck. You are using pg_query, you KNOW it's a Postgres
database, you should KNOW that Postgres creates boolean columns as char(1),
and that it uses a 't' to represent "true" and a 'f' to represent "false".
To overcome this failure I had to do the following in my class:-
$my_bool = this->colC? 't' : 'f';
and then use '$my_bool' instead of this->colC in the insert and update
statements.
Imagine if you had dozens of boolean type columns in a table. A nightmare.
It is quite common in applications where users belong to groups and a group
has a set of privileges, and those privileges are usually held as boolean
value's.
---
>From manual page:
http://www.php.net/function.pg-query#refsect1-function.pg-query-description
---
Actual result:
--------------
[Thu Jun 21 02:50:31 2012] [error] [client 127.0.0.1] PHP Warning:
pg_query(): Query failed: ERROR: syntax error at or near
","\nLINE 5: '', 'Kemly plus vistors to look at
house', , 0,\n
^ in /var/www/timemanager.info/public_html/classes/AppointMents.php on line
133, referer: http://dev.timemanager.info/addchgappnts.html
--
Edit bug report at https://bugs.php.net/bug.php?id=62405&edit=1
--
Try a snapshot (PHP 5.4):
https://bugs.php.net/fix.php?id=62405&r=trysnapshot54
Try a snapshot (PHP 5.3):
https://bugs.php.net/fix.php?id=62405&r=trysnapshot53
Try a snapshot (trunk):
https://bugs.php.net/fix.php?id=62405&r=trysnapshottrunk
Fixed in SVN:
https://bugs.php.net/fix.php?id=62405&r=fixed
Fixed in SVN and need be documented:
https://bugs.php.net/fix.php?id=62405&r=needdocs
Fixed in release:
https://bugs.php.net/fix.php?id=62405&r=alreadyfixed
Need backtrace:
https://bugs.php.net/fix.php?id=62405&r=needtrace
Need Reproduce Script:
https://bugs.php.net/fix.php?id=62405&r=needscript
Try newer version:
https://bugs.php.net/fix.php?id=62405&r=oldversion
Not developer issue:
https://bugs.php.net/fix.php?id=62405&r=support
Expected behavior:
https://bugs.php.net/fix.php?id=62405&r=notwrong
Not enough info:
https://bugs.php.net/fix.php?id=62405&r=notenoughinfo
Submitted twice:
https://bugs.php.net/fix.php?id=62405&r=submittedtwice
register_globals:
https://bugs.php.net/fix.php?id=62405&r=globals
PHP 4 support discontinued:
https://bugs.php.net/fix.php?id=62405&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=62405&r=dst
IIS Stability:
https://bugs.php.net/fix.php?id=62405&r=isapi
Install GNU Sed:
https://bugs.php.net/fix.php?id=62405&r=gnused
Floating point limitations:
https://bugs.php.net/fix.php?id=62405&r=float
No Zend Extensions:
https://bugs.php.net/fix.php?id=62405&r=nozend
MySQL Configuration Error:
https://bugs.php.net/fix.php?id=62405&r=mysqlcfg