Zend Framework converts a NULL string to an actual NULL value for MySql

Somehow, when importing data into mysql using multi-line insert with the execute () function, there were many rows added with a NULL string for some columns. How to convert these NULL strings to MySQL NULL values ​​so that I can check for empty values ​​using is_null () in php when displaying data.

How can I avoid this problem? I used the quote () function for each piece of data. Was there a problem using quotes on empty fields? I imported the csv file.

Thank you

+4
source share
1 answer

To insert SQL NULL or any other expression, you can use the Zend_Db_Expr object. Even if you use quote() , ZF passes these objects through unquoted.

 $null = new Zend_Db_Expr("NULL"); $table = new MyTable(); $table->insert(123, "abc", $null); 

Please note that since using Zend_Db_Expr circumvents both quoting and parameterization, you are responsible for protecting against SQL injection.


This is for your question, but consider LOAD DATA INFILE if you are uploading a large download CSV file. This can be 20 times faster than using multiple INSERT lines.

+9
source

Source: https://habr.com/ru/post/1299331/


All Articles