php - Integer inserting as 0 instead of NULL -


when insert null mysql integer field via php prepared statement inserts 0.

i have searched similar questions , have update code still having problem.

in code, if text box sends empty string php; php converts null ie.

$v3 = (strlen($v3)<1 ) ? null : $v3; 

as example, result in unit column null.

the prepare statement

$stmt = $mysqli->prepare("insert address ( `person`, `type`, `unit`, `street_num`, `street`, `street_type`, `suburb`, `state` ) values (?,?,?,?,?,?,?,?)")); 

bind parameter integer

$stmt->bind_param('isiissss',$p, $add_type[$a], $unit[$a], $street_num[$a], $street_name[$a], $street_type[$a], $suburb[$a], $state[$a]); 

in mysql, address.unit nullable , has no default value.

if insert directly table , omit value unit column; null stored. expected.

i suspect bind_param function changes null 0 if datatype column specified 'i' (integer), because nulls passed varchar columns stored null. correct , if how should pass null integer column?

to simplify question (and because didn't think relevant) omitted values passing through $mysqli->real_escape_string function , after testing found converts null empty string

$test = ""; $test = (strlen($test)<1 ) ? null : $test; var_dump($test); // null echo "<br>"; $test = $mysqli->real_escape_string($test); var_dump($test);  // string '' (length=0) 

this not solve problem answer question


Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -