简体   繁体   中英

how to use nullif() in a query in a php form

I try to import a csv file in a table in PostgreSQL 13 and php form ( beginner ).
There are two foreign keys integer type in the table, one can be empty. So when I import the file I have the common message invalid input syntax for type integer for one of them.
Following this post , NullIf() function seems to be a simple solution.

I can't find the right way to use it in:

$sql = "INSERT INTO activite.us (numus, gidgeo, gidaxe)
        VALUES ('".$getData[0]."','".$getData[10]."', NULLIF('".$getData[11]."', '') " ;

The foreign key is the last variable.

  • I tried to replace second arg with NULL;
  • I tried 'NULLIF("...")' and some others false combo.

How to fix that? Thanks.

(Even if PDO would be better,) an answer is

NULLIF('".$getData[11]."', '')::integer)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM