Thursday, January 13, 2022

[FIXED] How to copy data (datatype BLOB) into another table?

Issue

I want to copy data from blob to another table in the same data type blob but it turns to

You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '???q}??I=|(T???>?????77j{{???~?>O??i?:??Ѹ>??~ݻw??_????㷈???Q/?8l>? XW?c' at line 1

As I discovered, the imageDesign cannot be transferred because of the data are too long because if the data is only 1.7KiB, it can be transferred. Please help me for my fyp project

$query = "SELECT * FROM cart where userID = '$user_id'";  
    $result = mysqli_query($con, $query);  
    $countOrd =  mysqli_num_rows($result);
    if(mysqli_num_rows($result) > 0)  
    {  
         while($row = mysqli_fetch_array($result))  
         {
             $productQuantity = $row["productQuantity"];
             $productID = $row["productID"];
             $productSize = $row["productSize"];
             $productColour = $row["productColour"];
             $designType = $row["designType"];
             $readymadeID = $row["readymadeID"];
             $imageDesign = $row["imageDesign"];

    $add_query ="INSERT INTO orders(userID,productID,productSize,productColour,orderQuantity,designType,readymadeID,imageDesign,orderPayment,orderStatus,orderDate,orderTime) values ('$user_id','$productID','$productSize','$productColour','$productQuantity','$designType','$readymadeID','$imageDesign','$payment','Pending','$orderDate','$orderTime')";
    $delete_query="DELETE from cart where userID='$user_id'";
    $add_query_result=mysqli_query($con,$add_query) or die(mysqli_error($con));
    $delete_query_result=mysqli_query($con,$delete_query) or die(mysqli_error($con));
    }}

Solution

Blob-Data will not work with dynamic-adhoc-sql (which is to be avoided at any cost anyway). A very good guide on working with blob-data (and the mandatory parameter-binding): MySQL & Blob



Answered By - Michael Hauptmann

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.