将blob从一个表复制到另一个表

时间:2015-03-18 15:59:47

标签: php mysql

我正在尝试将一些列数据从一个表移动到另一个表。 一切都在移动,但图像(blob)从未复制到新位置。我已经更新了我的代码,用一个新的ID将图像从一个表移动到另一个表。

这是我的疑问:

<?php


logit("\nSwap Lane\n");

$camTable = $_POST['cam'];
$plate = $_POST['plate'];
$id = $_POST['id'];
$tmp = explode("-", $id);
$tableEntryId = $tmp[0];

$tmp= explode('_anpr_vega', $camTable);
$camName = $tmp[0];
if ($camName == "archive")
  {
    print "{\"iv\":\n";
    print "  { \"result\": \"FAILED\"} \n";
    print "}\n";
    exit;
  }

print "{\"iv\":\n";

$custId = $_SESSION['customerID'];
$userId = $_SESSION['userId'];

if ($custId != "") 
  {
    $conn = &newEtConn($custId);

    if ($camTable != "archive") 
      {
        $camId = etCommonCamIdByName($camName);
        $inOut = etCommonInOutByCamId($camId);
        $cpId = etCommonSiteIdByCamId($camId);
        $staticWhitelist = etCommonMkWhiteList($conn, $cpId);

        if ($inOut == 1) 
          {
            $camColumn = "in_cam_id";
            $entryColumn = "in_entry_id";
            $datetimeColumn = "in_datetime";
            $otherColumn = "out_cam_id";
            $otherEntry = "out_entry_id";
            $otherDatetime = "out_datetime";
            $otherType = 2;
        $new_cam_id_array = etCommonAllOutCamIdsByCamId($camId);
        $myDateColumn = "in_datetime";
        $otherDateColumn = "out_datetime";
          }
        else if ($inOut == 2) 
          {
            $camColumn = "out_cam_id";
            $entryColumn = "out_entry_id";
            $datetimeColumn = "out_datetime";
            $otherColumn = "in_cam_id";
            $otherEntry = "in_entry_id";
            $otherDatetime = "in_datetime";
            $otherType = 1;
        $new_cam_id_array = etCommonAllInCamIdsByCamId($camId);
        $myDateColumn = "out_datetime";
        $otherDateColumn = "in_datetime";
          }

    $new_cam_id = $new_cam_id_array[0];
    $new_cam_name = etCommonCamNameById($new_cam_id);
    $newCamTable = $new_cam_name . "_anpr_vega";

    // Find the reconcile entry
    $sql = "SELECT id, plate, in_cam_id, out_cam_id, $myDateColumn AS my_datetime FROM customer_1.reconcile WHERE $camColumn = \"$camId\" AND $entryColumn = \"$tableEntryId\" LIMIT 1";
    $result = $conn->Execute($sql);
    $row = $result->fields;
    $reconcileId = $row['id'];
    $recon_in_cam_id = $row['in_cam_id'];
    $recon_out_cam_id = $row['out_cam_id'];
    $recon_plate = $row['plate'];
    $recon_datetime = $row['my_datetime'];
    $tmp = explode(" ", $recon_datetime);
    $entry_date = $tmp[0];
    $entry_time = $tmp[1];

    // Put the entry into the other table
    $sql = "INSERT INTO $newCamTable (plate, nread, datetime, millisecs, nationality, image_name, image) SELECT plate, nread, datetime, millisecs, nationality, image_name, image FROM $camTable WHERE id=\"$tableEntryId\"";
    logit($sql);
    $result = $conn->Execute($sql);
    if (!$result) 
      {
        print $conn->ErrorMsg();
      }

    $sql = "SELECT id FROM $newCamTable ORDER BY id DESC";
    $result = $conn->Execute($sql);
    if (!$result) 
      {
        print $conn->ErrorMsg();
      } 
    $row = $result->fields;
    $newId = $row['id'];

    $sql = "UPDATE $newCamTable SET name=\"$new_cam_name\", camera_id=\"$new_cam_id\" WHERE id=\"$newId\"";
    logit($sql);
    $result = $conn->Execute($sql);
    if (!$result) 
      {
        print $conn->ErrorMsg();
      }







    $sql = "UPDATE $newCamTable SET plate=\"$plate\", checked=\"1\" WHERE id=$newId";
    logit($sql);
    $result = $conn->Execute($sql);
    if (!$result) 
      {
        print $conn->ErrorMsg();
      }
      }
  }


print "  { \"result\": \"OK\", \n";
print "     \"data\": [\n";
print "        {\"plate\": \"$plate\"}";
print "\n    ]\n  }\n}\n";
?>

0 个答案:

没有答案