PHP Classes

Question about inserting empty string into varchar

Recommend this page to a friend!

      Extended MySQLi  >  All threads  >  Question about inserting empty...  >  (Un) Subscribe thread alerts  
Subject:Question about inserting empty...
Summary:Using $param=""; $db->query($sql, $param) results in '0' in col
Messages:4
Author:Andrew Johnson
Date:2013-10-01 15:11:58
Update:2013-10-04 20:52:51
 

  1. Question about inserting empty...   Reply   Report abuse  
Picture of Andrew Johnson Andrew Johnson - 2013-10-01 15:11:58
Hi there.

(Sorry this is a version 3 question)

Is there any reason why trying to insert an empty string into a varchar column might result in a character zero being inserted instead?

Any help would be appreciated!

  2. Re: Question about inserting empty...   Reply   Report abuse  
Picture of Andrew Johnson Andrew Johnson - 2013-10-01 15:34:55 - In reply to message 1 from Andrew Johnson
(more specifically version 3.0.0 $Rev: 642)

  3. Re: Question about inserting empty...   Reply   Report abuse  
Picture of Andrew Johnson Andrew Johnson - 2013-10-02 09:56:39 - In reply to message 2 from Andrew Johnson
I think I may have partly answered this for myself. By setting the variable to NULL if this is an empty string, then the query method passes the NULL correctly to the database.

Still remains that passing an empty string adds 0 to a varchar column. Looking in the code for the class, I see that the values passed are tested for type and is_string() should identify an empty string correctly as a string type.

  4. Re: Question about inserting empty...   Reply   Report abuse  
Picture of Camilo Sperberg Camilo Sperberg - 2013-10-04 20:52:51 - In reply to message 3 from Andrew Johnson
Sorry if it took me a while to get back to you, but I haven't got any notifications of your posts.

What you mention is indeed a huge problem with v3.X. It is completely solved however in v4.0+, which in general has huge improvements over v3.0.

My recomendation would be that you update to v4.

You are also very welcome to leave comments on Github, where I do get notifications:
github.com/unreal4u/db_mysqli

Greetings.

 
For more information send a message to info at phpclasses dot org.