1

I have a query that aliases a bunch of column names, and some of the aliases are on the long side (40-50 characters). Locally, everything works fine, but when I run the same code in the testing environment, the database results are returned with the keys limited to 31 characters.

The query code is pretty much out-of-the-box CI:

$query = $this->database->query($sql);

if ($query->num_rows() > 0) {
    $result = $query->result_array();
    print_array($result); // pre and print_r
}

Everything I've read suggests PHP doesn't limit the length of an array key so - is this a Codeigniter thing? Or does PHP usually not limit it (is there a setting that can and is here)?

Chords
  • 6,720
  • 2
  • 39
  • 61

2 Answers2

1

This is not a problem of PHP, but a problem with the database. The database (oracle?) does limit the length of column and table identifiers to 32 bytes, which is 31 chars and the null byte.

Please consult your database server administrator to find out whether you can extend the limit.

pgampe
  • 4,531
  • 1
  • 20
  • 31
  • I thought this might be the case (it's a Vertica database) but why would it not do the same thing in the local environment? Shouldn't I see that across the board? – Chords May 28 '14 at 15:36
  • Not if you are using a different database, e.g. mysql instead of oracle. You server settings might be different too. – pgampe May 28 '14 at 15:49
  • I guess I should be more clear, sorry (and thanks for following up) - the code is on different environments, but both environments are querying the same database instance. Would that eliminate the database limit being the issue? – Chords May 28 '14 at 15:56
  • If you use a different database driver, this might matter. – pgampe May 30 '14 at 13:47
0

This actually IS a PHP issue. The bug can be found here:

https://bugs.php.net/bug.php?id=44003

And a prior ask on SO here:

PHP & SQL Server - field names truncated

Fix requires re-compiling PHP, unfortunately.

Community
  • 1
  • 1
Chords
  • 6,720
  • 2
  • 39
  • 61