php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #10121 Case Sensitive Associative Arrays
Submitted: 2001-04-02 16:11 UTC Modified: 2001-05-22 07:05 UTC
From: dranor at dracon dot net Assigned:
Status: Closed Package: PostgreSQL related
PHP Version: 4.0.4pl1 OS: Redhat Linux 7.0
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: dranor at dracon dot net
New email:
PHP Version: OS:

 

 [2001-04-02 16:11 UTC] dranor at dracon dot net
The scenario is described here:

mydb=> CREATE TABLE test ( U_Name char(50), U_Pass char(16) );
mydb=> INSERT INTO test values ('Bob', 'password');

query.php:

<?
$conn = pg_connect("dbname=mydb");
$result = pg_exec($conn, "select U_Name, U_Pass from test")
$arr = pg_fetch_array($result, 0);
echo "U_Name: " + $arr[U_Name] + " U_Pass: " + $arr[U_Pass] + "<BR>";
echo "u_name: " + $arr[u_name] + " u_pass: " + $arr[u_pass] + "<BR>";
?>

results that are printed:U_Name:  U_Pass: 
                         u_name: Bob u_pass: password

( arr[0] = Bob, arr[1] = password)


U_Name is not being automatically lowercased when using associative arrays.  As of v6.1 PostgreSQL lowercases all table names as well as all columns.  So searching on mixed case or uppercase names will not work unless they are enclosed in quotes..

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-04-02 17:27 UTC] dranor at dracon dot net
Rereading that last line its a little confusing.
If you want to input table or column names as mixed case you need to enclose them in quotes otherwise they are lowered.  Then when you make a query you would also need to enclose the query names in quotes as it is also lowered automatically if there are no quotes.  However this behavior is not shared by associative arrays in PHP for some reason.
 [2001-04-02 17:49 UTC] dranor at dracon dot net
Rereading that last line its a little confusing.
If you want to input table or column names as mixed case you need to enclose them in quotes otherwise they are lowered.  Then when you make a query you would also need to enclose the query names in quotes as it is also lowered automatically if there are no quotes.  However this behavior is not shared by associative arrays in PHP for some reason.
 [2001-05-22 07:05 UTC] swm@php.net
This query performs exactly as it should. If you had have enclosed the create table columns in quotes, they would have been treated case sensitively (in the create and subsequently in the query) as well as by the associative array. Your query proves this.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 19:01:28 2024 UTC