我在表A中有很多列: 例如:
temperature character varying(5),
atmosphericpressure integer,
humidity integer,
perceptiondistinction1_cd character varying(6),
perceptiondistinction2_cd character varying(6),
timeprogress character varying(1),
telegramreceived_datetime timestamp without time zone,
order_datetime timestamp without time zone,
outbreak_datetime timestamp without time zone,
locationarrival_datetime timestamp without time zone,
touch_datetime timestamp without time zone,
insidecar_datetime timestamp without time zone,
starting_datetime timestamp without time zone,
hospitalarrival_datetime timestamp without time zone,
hospitalaccommodate_datetime timestamp without time zone,
pulling_datetime timestamp without time zone,
return_datetime timestamp without time zone,
spotdistance integer,
spottohospital integer,
returnstationdistance integer,
receiveorderplace_cd character varying(6),
changehospital1medicalsystem_cd character varying(6),
requestorganization_cd character varying(6),
changehospital1openincident_cd character varying(6),
requestorganizationname character varying(120),
doctorfellowpassenger character varying(1),
changehospitalreason_cd character varying(6),
nottransportation_cd character varying(6),
coodinationdoctorcar character varying(6),
entrydoctorcarhelicopterrequest_cd character varying(6),
entryoperation_cd character varying(6),
entrymultiplexcooperation_cd character varying(6),
partymember1 integer,
ownambulancecount integer,
paramedicembarkation_cd character varying(6),
paramedicclassication_cd character varying(6),
doctoremvarkation_cd character varying(6),
preventiongloves character varying(1),
preventiongoggles character varying(1),
preventionmask character varying(1),
preventiongown character varying(1),
spotbreathingset character varying(1),
carryoxygen character varying(1),
carryaspirator character varying(1),
carrydefibrillator character varying(1),
spotexternalwoundset character varying(1),
spotcervicalspine character varying(1),
carrybackboard character varying(1),
spotstretcher character varying(1),
carryother character varying(1),
switchingdivision_cd character varying(6),
switchingdelivery_cd character varying(6),
reportsuddenly character varying(1),
reportsnore character varying(1),
reportgiddiness character varying(1),
reportconsciousness character varying(1),
reportconsciousness_cd character varying(6),
reportbath character varying(1),
reportconvulsion character varying(1),
reporttoilet character varying(1),
reportindeisposed character varying(1),
reportmeal character varying(1),
reportentrance character varying(1),
reporthematemesis character varying(1),
reportheratdisease character varying(1),
reportheart character varying(1),
reportbreath character varying(1),
reportbreath_cd character varying(6),
reportvomiting character varying(1),
reportrespiratorydscomfort character varying(1),
reportpainful character varying(1),
reporthurt character varying(1),
reportslurring character varying(1),
reportsufferingheart character varying(1),
reportchestpain character varying(1),
reportstomachache character varying(1),
reportheadache character varying(1),
reportlumbago character varying(1),
reportbackache character varying(1),
reportconversation character varying(1),
reportconversation_cd character varying(6),
reportnotstand character varying(1),
reporthypoglycemia character varying(1),
reportnotexstinghouse character varying(1),
reportdrink character varying(1),
reporttemperature character varying(1),
reportindooroutdoor character varying(1),
reportindooroutdoor_cd character varying(6),
reportasthma character varying(1),
oralinstruction_cd character varying(6),
instructionon_cd character varying(6),
instructionoff_cd character varying(6),
oralguidanceambulanceteam character varying(1),
oralguidancedirector character varying(1),
oralguidancedirector_cd character varying(6),
victimrespiratorysubstance character varying(1),
victimnoconsciousness character varying(1),
victimnotmove character varying(1),
victimchestpain character varying(1),
victimdyspnea character varying(1),
victimextenalhemorrhage character varying(1),
victimother character varying(1),
guidancecontetsobservation character varying(1),
guidancecontetsposition character varying(1),
guidancecontetsairway character varying(1),
guidancecontetsremoval character varying(1)
对于列整数或时间戳,如果值为'',则在插入或更新时将出错。例如:
$atmosphericpressure ='';
$humidity ='';
$order_datetime='';
$outbreak_datetime='';
$locationarrival_datetime ='';
Update A set atmosphericpressure ='$atmosphericpressure',humidity = '$humidity',order_datetime='$order_datetime',outbreak_datetime='$outbreak_datetime',...
变量的设定值如何是DBNull?
答案 0 :(得分:1)
您可以编写一个函数将字符串转换为数据库表达式:
function toDB($string) {
if ($string == '') {
return 'null';
} else {
return "'$string'";
}
}
并使用它来创建您的查询:
$sql = "Update A set atmosphericpressure = {toDB($atmosphericpressure)},humidity = {toDB($humidity)},order_datetime= {toDB($order_datetime)},...";
根据项目的大小,最好通过使用对象关系映射器来抽象数据库访问,可以在this question中找到一些建议。