Php-script processes in turn all the rows of the sample through the function mysqli_fetch_assoc . If certain conditions are met - the value in the row must be updated. With this task, I have no problems when there is a column of type ID:

 while($row=mysqli_fetch_assoc($result)){ if ($row["data"]==$condition) mysqli_query($connection,"UPDATE `$table` SET `data` = '$newdata' WHERE `$table`.`ID` = '".$row["ID"]."';"); } 

But if the table consists of just one 'data' column, without the 'ID' column? Is it possible for a php script to update the value of exactly the series that was obtained through the function mysqli_fetch_assoc ?

If not, please tell me another way how such an update of the data in the table could be done from one column (to save the php script a cycle in which the condition is checked with each row).

  • If the volume is small - take the data, do with it what you want in the script, filter ... And then do the drop table , create table , insert into ...... without the truncate tablel -> insert into drop .. because the update should be done according to some condition ..... if the data fields are not unique, there is nothing to attach to ..... and in principle, a table with one field is meaningless as such - Alexey Shimansky
  • @ Alexey Shimansky Yes, I understand that a table with one field is meaningless, just the script will work with tables in which the structure may differ, and the identification field may be called differently. At the same time, large-size tables can be processed (specific example: wp_posts table from wordpress database with several hundred entries), mysqli_fetch_assoc function - shows good performance results and satisfies everyone until the structure of the database being processed is known. - federk
  • @ AlekseyShimansky If I have a table with a total volume of 10MB, is the method you indicated acceptable? And if 100MB (this is already hypothetical)? To work with an array of such volume, will additional PHP memory be required, or will the interpreter need exactly as much RAM as the table occupies? - federk
  • one
    Well, it is impossible to recreate tables on a work base. They may contain fields of type autoincrement in which you will not insert old data, but they may be referenced. So the script should, through the schema description tables, obtain information about the primary key and give an update based on it. Option 2: select * and create update set все-колонки where все-колонки=старым-значениям - Mike
  • one
    It is not necessary to push values ​​into the request text. Better to put a bunch of '?' instead of all the inline values ​​and linking the values ​​to them php.net/manual/ru/mysqli-stmt.bind-param.php - Mike

1 answer 1

In the comments, Mike suggested the best option for solving this problem:

 while($row=mysqli_fetch_assoc($result)){ if ($row["data"]==$condition) { $stmt = mysqli_prepare($connection, "UPDATE `".$table."` SET `data` = ? WHERE `".$table."`.`data`=?"); mysqli_stmt_bind_param($stmt, 'ss', $newdata, $originaldata); mysqli_stmt_execute($stmt); } 

If there are Russian characters in the data and they are in UTF-8, then before that you still need to register:

 mysqli_set_charset($connection,'utf8');