Note that there are some explanatory texts on larger screens.

plurals
  1. POFind "problematic" rows in a mysql table that will fail to export
    primarykey
    data
    text
    <p>I wanted to <a href="http://davidwalsh.name/backup-mysql-database-php" rel="nofollow noreferrer">backup my database with PHP</a>.</p> <p>I tested the linked script but it was never ending, I tried to prepend the <code>repair $table</code> before the query but it didn't help.</p> <p>So I figured out if I just skip two tables (you can see in the code) then it works fine:</p> <pre><code>&lt;? error_reporting(E_ALL); ini_set('error_reporting',1); require('../basedatos.php'); echo 'included&lt;br&gt;'; /* backup the db OR just a table */ function backup_tables($host,$user,$pass,$name,$tables = '*') { echo '1&lt;br&gt;'; //get all of the tables if($tables == '*') { $tables = array(); $result = mysql_query('SHOW TABLES') or die(msyql_error()); while($row = mysql_fetch_row($result)) { $tables[] = $row[0]; } } else { $tables = is_array($tables) ? $tables : explode(',',$tables); } echo '2&lt;br&gt;'; //cycle through foreach($tables as $table) { if($table == 'etiquetas' || $table == 'links') continue; $repair = mysql_query("REPAIR table $table") or die(mysql_error()); echo '3- '.$table.'&lt;br&gt;'; $result = mysql_query('SELECT * FROM '.$table) or die(msyql_error()); $num_fields = mysql_num_fields($result); $return.= 'DROP TABLE '.$table.';'; $row2 = mysql_fetch_row(mysql_query('SHOW CREATE TABLE '.$table)) or die(msyql_error()); $return.= "\n\n".$row2[1].";\n\n"; for ($i = 0; $i &lt; $num_fields; $i++) { while($row = mysql_fetch_row($result)) { $return.= 'INSERT INTO '.$table.' VALUES('; for($j=0; $j&lt;$num_fields; $j++) { $row[$j] = addslashes($row[$j]); $row[$j] = ereg_replace("\n","\\n",$row[$j]); if (isset($row[$j])) { $return.= '"'.$row[$j].'"' ; } else { $return.= '""'; } if ($j&lt;($num_fields-1)) { $return.= ','; } } $return.= ");\n"; } } $return.="\n\n\n"; } echo '4&lt;br&gt;'; //save file $handle = fopen('db-backup-'.time().'-'.(md5(implode(',',$tables))).'.sql','w+'); fwrite($handle,$return); fclose($handle); } backup_tables('localhost','username','password','*'); ?&gt; </code></pre> <p>Is there any way to find the rows that are giving me a problem so I can edit/delete them?</p> <p>-PS-</p> <p>Also, I don't get any errors if I don't skip them (the script just never gets to the end, that's why I added some ugly logs.., any idea why?</p> <p>-EDIT-</p> <p>Also, if I try to export the database via, for example, sqlBuddy I also get errors:</p> <p><img src="https://i.stack.imgur.com/F2cE4.png" alt="enter image description here"></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload