It is necessary to copy BLOB data from one table to another, but for some reason they are not transferred. They come, but for some reason they are not recorded.

while($row = mysqli_fetch_array($q)) { $sql_bx="insert into usr_files (FILENAME, FBID, TYPE, FILE) values( '".$row['FILENAME']."', '".$row['FBID']."', '".$row['TYPE']."', '".$row['FILE']."');"; mysqli_query($db_bx_link, $sql_bx); echo mysqli_error($db_bx_link); break; } 

The $ row ['FILE'] contains this data.

Mistake: enter image description here

 while($row = mysqli_fetch_array($q)) { $stmt = mysqli_prepare($db_bx_link, "INSERT INTO usr_files VALUES (?, ?, ?, ?)"); mysqli_stmt_bind_param($stmt, 'sssd', $code, $language, $official, $percent); $code = $row['FILENAME']; $language = $row['FBID']; $official = $row['TYPE']; $percent = $row['FILE']; mysqli_stmt_execute($stmt); printf("%d строк вставлено.\n", mysqli_stmt_affected_rows($stmt)); break; } 

Answer: 0 lines inserted

  • one
    because you substitute variable values ​​directly into the query. You write values( 'X' ) and if this X is equal to for example xx 'abc' xx then the final string contains extra quotes. Never substitute values ​​directly into a query, always use prepared expressions and bind values php.net/manual/ru/mysqli-stmt.bind-param.php - Mike
  • one
    In general, the transfer of data from one table to another must be done not in php, but in one sql-query insert ... select ... - Mike
  • Rewrote on the manual, the result is still no. Or did something wrong? - gubin
  • "In general, the transfer of data from one table to another must be done not with php, but with one sql query," the fact is that this procedure needs to be done on krone once a day. - gubin
  • The request can be made from php, also on krone, once a day. Only no cycles are needed. In addition, mysql has its own task scheduler habr.com/ru/post/123391 and it will perfectly cope with the task without crown and php - Mike

0