Welcome Guest, Not a member yet? Register   Sign In
Inserting into DB when when the value is empty
#1

[eluser]George36[/eluser]
Hi There,

I'm using the db->insert('tablename', $data); function to add XML data to a database.

Sometimes, however, an XML field does not contain any data, so it results in an INSERT statement that may look like this:

Code:
INSERT INTO table_name (column1, column2, column3,...)
VALUES (value1, , value3,...)


Ideally, it would look like this:
Code:
INSERT INTO table_name (column1, column2, column3,...)
VALUES (value1,'' , value3,...)


Do I need to test each value to check it for null data before I build the data array, or is there a better way?

Many thanks

George
#2

[eluser]jtkendall[/eluser]
If you have the query hard coded so that it always expects col1, col2, and col3, then checking each for null data would probably be the best option.




Theme © iAndrew 2016 - Forum software by © MyBB