PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » Database » DB » Bug #585

query() fails with params is assoc array

Details

Submitted2004-01-15 21:52 UTC
Frommackking at canada dot com
Assigneddanielc
StatusClosed
PackageDB
PHP Version4.3.3
OSLinux
Roadmaps(Not assigned)

Comments

[2004-01-15 21:52 UTC] mackking at canada dot com

Description:
------------
If the array of parameters you provide to DB_common::query() (and I assume DB_common::execute()) is a non-sequential non-number array, the query fails.

I'm pretty sure this stems from the fact that executeEmulateQuery() accesses the members of the array from within a for loop and using a numerical index.

The only reason I caught this is because of NOT NULL constraints on some of my fields.

Reproduce code:
---------------
// assuming: create table link ( url varchar(50) not null, name varchar(50));

$data = array('url'=>'http://pear.php.net', 'name'=>'Pear Code Library');

$res = $DBH->query("INSERT INTO link SET url=?, name=?", $data);

Expected result:
----------------
That the array would still be usable regardless of the fact that the indexes of the data I want stored aren't digits from 0 - n.

Actual result:
--------------
db_error Object
(
[error_message_prefix] =>
[mode] => 1
[level] => 1024
[code] => -3
[message] => DB Error: constraint violation
[userinfo] => INSERT INTO link SET url=NULL, name=NULL [nativecode=1048 ** Column 'url' cannot be null]
[backtrace] => Array
(
[0] => Array
(
[file] => /usr/share/pear/DB.php
[line] => 642
[function] => pear_error
[class] => db_error
[type] => ->
[args] => Array
(
[0] => DB Error: constraint violation
[1] => -3
[2] => 1
[3] => 1024
[4] => INSERT INTO link SET url=NULL, link_en=NULL, link_fr=NULL, weight=NULL [nativecode=1048 ** Column 'url' cannot be null]
)

)

[1] => Array
(
[file] => /usr/share/pear/PEAR.php
[line] => 525
[function] => db_error
[class] => db_error
[type] => ->
[args] => Array
(
[0] => -3
[1] => 1
[2] => 1024
[3] => INSERT INTO link SET url=NULL, link_en=NULL, link_fr=NULL, weight=NULL [nativecode=1048 ** Column 'url' cannot be null]
)

)

[2] => Array
(
[file] => /usr/share/pear/DB/common.php
[line] => 298
[function] => raiseerror
[class] => pear
[type] => ::
[args] => Array
(
[0] =>
[1] => -3
[2] =>
[3] =>
[4] => INSERT INTO link SET url=NULL, link_en=NULL, link_fr=NULL, weight=NULL [nativecode=1048 ** Column 'url' cannot be null]
[5] => DB_Error
[6] => 1
)

)

[3] => Array
(
[file] => /usr/share/pear/DB/mysql.php
[line] => 698
[function] => raiseerror
[class] => db_mysql
[type] => ->
[args] => Array
(
[0] => -3
[1] =>
[2] =>
[3] =>
[4] => 1048 ** Column 'url' cannot be null
)

)

[4] => Array
(
[file] => /usr/share/pear/DB/mysql.php
[line] => 224
[function] => mysqlraiseerror
[class] => db_mysql
[type] => ->
[args] => Array
(
)

)

[5] => Array
(
[file] => /usr/share/pear/DB/common.php
[line] => 563
[function] => simplequery
[class] => db_mysql
[type] => ->
[args] => Array
(
[0] => INSERT INTO link SET url=NULL, link_en=NULL, link_fr=NULL, weight=NULL
)

)

[6] => Array
(
[file] => /usr/share/pear/DB/common.php
[line] => 758
[function] => execute
[class] => db_mysql
[type] => ->
[args] => Array
(
[0] => 1
[1] => Array
(
[url] => http://www.google.com/
[link_en] => Google Search
[link_fr] => Recherche Google
[weight] => 5
)

)

)

[7] => Array
(
[file] => /home/mack/public_html/awpi/jb/src/database.inc
[line] => 35
[function] => query
[class] => db_mysql
[type] => ->
[args] => Array
(
[0] => INSERT INTO link SET url=?, link_en=?, link_fr=?, weight=?
[1] => Array
(
[url] => http://www.google.com/
[link_en] => Google Search
[link_fr] => Recherche Google
[weight] => 5
)

)

)

[8] => Array
(
[file] => /home/mack/public_html/awpi/jb/src/admin.inc
[line] => 187
[function] => db_insertxby
[args] => Array
(
[0] => link
[1] => Array
(
[url] => http://www.google.com/
[link_en] => Google Search
[link_fr] => Recherche Google
[weight] => 5
)

)

)

[9] => Array
(
[file] => /home/mack/public_html/awpi/jb/src/admin.inc
[line] => 134
[function] => _linksedit
[args] => Array
(
[0] => Array
(
[url] => http://www.google.com/
[link_en] => Google Search
[link_fr] => Recherche Google
[weight] => 5
)

)

)

[10] => Array
(
[file] => /home/mack/public_html/awpi/jb/src/admin.inc
[line] => 39
[function] => admin_links
[args] => Array
(
[0] => Array
(
[url] => http://www.google.com/
[link_en] => Google Search
[link_fr] => Recherche Google
[weight] => 5
)

)

)

[11] => Array
(
[file] => /home/mack/public_html/awpi/jb/src/index.php
[line] => 20
[function] => admin_page
[args] => Array
(
)

)

)

[callback] =>
)

)