Posts

Mysql : Incorrect datetime value: '0000-00-00 00:00:00'

  SET SQL_MODE = 'ALLOW_INVALID_DATES' ;

error: Fatal error: Uncaught mysqli_sql_exception: Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column

Error: Fatal error : Uncaught mysqli_sql_exception: Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column Solution: mysqli_query($con, "SET sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));");

MySQL and PHP - insert NULL rather than empty string

 Method 1: $query = "INSERT INTO uradmonitor (db_value1, db_value2) VALUES (" . (($val1== '' )? "NULL" :( "'" .$val1. "'" )) . ", " . (($val2== '' )? "NULL" :( "'" .$val2. "'" )) . ")" ; Method 2: INSERT INTO table VALUES ( '' , NULLIF ( '$date' , '' )) Method 3: $intLat = ! empty ( $intLat ) ? "' $intLat '" : NULL ; $intLng = ! empty ( $intLng ) ? "' $intLng '" : NULL ;