Example :
$query = "INSERT INTO uradmonitor (db_value1, db_value2) VALUES (".
(($val1=='')?"NULL":("'".$val1."'")) . ", ".
(($val2=='')?"NULL":("'".$val2."'")) .
")";
$result = mysql_query($query);
From This http://stackoverflow.com/questions/4620391/mysql-and-php-insert-null-rather-than-empty-string
Example on internet : RP/rp_recreatecopy.php
Example on internet : RP/rp_recreatecopy.php
$SQL = "INSERT INTO sci_rp.RPHeader(RPID, RequestDate, CreateDate, Creator, PREmployee, RPSupervisor, RPManager, PRSupervisor, PRManager, Director, Status, RequestLevel, EndDate) ";
$SQL .= " VALUES('".$NewID."','".$RequestDate."','".$CreateDate."','".$CreatorEmpId."',".(($PREmployee=='')?"NULL":("'".$PREmployee."'")).",".(($RPSupervisor=='')?"NULL":("'".$RPSupervisor."'")).",".(($RPManager=='')?"NULL":("'".$RPManager."'")).",".(($PRSupervisor=='')?"NULL":("'".$PRSupervisor."'")).",".(($PRManager=='')?"NULL":("'".$PRManager."'")).",".(($Director=='')?"NULL":("'".$Director."'")).",'".$Status."','".$HeaderData["RequestLevel"]."',".(($EndDate=='')?"NULL":("'".$EndDate."'")).")";
$myDB->Update($SQL);
Or use this method.
- Create tmp table in database. By copy table to new table by structure only.
- User SQL INSERT(SELECT * FROM ...)
Code Example :
- Create tmp table in database. By copy table to new table by structure only.
- User SQL INSERT(SELECT * FROM ...)
Code Example :
$SQL = "INSERT INTO sci_rp.RPHeader_tmp (SELECT * FROM sci_rp.RPHeader WHERE RPID='".$RPID."')";
$myDB->Update($SQL);
$SQL = "UPDATE sci_rp.RPHeader_tmp SET RPID='".$NewID."' WHERE RPID='".$RPID."'";
$myDB->Update($SQL);
$SQL = "INSERT INTO sci_rp.RPHeader(SELECT * FROM sci_rp.RPHeader_tmp WHERE RPID='".$NewID."')";
$myDB->Update($SQL);
$myDB->Update("DELETE FROM sci_rp.RPHeader_tmp WHERE RPID='".$NewID."'");
ไม่มีความคิดเห็น:
แสดงความคิดเห็น