Welcome Guest, Not a member yet? Register   Sign In
Why Do Empty Strings Get Converted to Single Spaces?
#1

[eluser]Bob Dog[/eluser]
Why is it that if I do a simple "get" on a table and display the results:

Code:
$query = $this->db->get('tblUsers');
var_dump($query->result());

the empty strings in the data get converted to single spaces:

Code:
array(1) {
  [0]=>
  object(stdClass)#27 (3) {
    ["intUserID"]=>
    int(1)
    ["txtUsername"]=>
    string(8) "somebody"
    ["txtName"]=>
    string(1) " "
  }

The txtName column is definitely an empty string in the database but it is being returned as a single space. Why the conversion? Is this something unique to me or do you all see the same thing?

This is with SQLServer and the txtName field is of type "varchar(255),null".

Thanks.
#2

[eluser]InsiteFX[/eluser]
Because you have a space in the " " should be ""

InsiteFX
#3

[eluser]Bob Dog[/eluser]
I don't know what you're talking about. The " " above is in the output of the var_dump() command. The problem is that empty strings in the database are being returned by the database get/result methods as single spaces. Why?
#4

[eluser]danmontgomery[/eluser]
Googled 'php mssql empty string' and found the answer to this on the first result, took less than 60 seconds.

http://drupal.org/node/194162

Quote:In case of MSSQL, fetching empty string '' by PHP will return as ' ' (a single space string). Surly that most if ($value->string == '') checking after db_fetch_array() and db_fetch_object() will result as buggy. This is due to PHP MSSQL driver implementation. This is a PHP driver level problem, PDO also can't help about this.




Theme © iAndrew 2016 - Forum software by © MyBB