<?php $host = '127.0.0.1'; $root = 'root'; $pass = 'XXX'; $dbna = 'test'; $conn = mysqli_connect($host,$root,$pass,$dbna); $name = null; $password = null; $name_en = null; $department = null; $position = null; $sql = "insert into person (name,password,name_en,department,position) value('$name','$password','$name_en','$department','$position ')"; if(mysqli_query($conn,$sql)){ echo ("创建成功"); }else{ echo (mysqli_error($conn)); } ?>
MYSQL数据库已设置都不允许NULL,通过PHP操作插入数据时,如果把null赋值给变量,然后通过变量插入,仍然能插入数据。
如果,直接设置null则会正常的提示不允许null值,
$sql = "insert into person (name,password,name_en,department,position) value('$name','$password','$name_en','$department',null)";
为什么通过变量形式还是能够插入null值
qq_ty_1
慕神6678310
天使之翼死神之镰
慕妹4267064
凯旋132
林子懿
QJAutumn
ZM77
风儿风光
Sun丶发发