vifito.eu

Web Development & Open Source

  • Aumentar o tamaño da fonte
  • Tamaño do texto por defecto
  • Diminuir o tamaño do texto

Correxindo as slashes inseridas por magic_quote con DatabaseIterator

Con DatabaseIterator podemos remover as slash dunha base de datos inseridas por ter a directiva magic_quote habilitada no php.ini


$conn = ADONewConnection('mysql');
$conn->PConnect('localhost', 'root', 's3cr3t', 'databasename');
// DatabaseIterator
$dbIt = new DatabaseIterator($conn);
// process tables
foreach($dbIt as $table) { 
    $columns = $table->getColumns();
    $i = 0;
 
    // process columns
    foreach($columns as $column) {
        if(!$column->isPK()) {
            $colName = $column->name;
 
            // Retrieve bad rows
            $rows = $table->select()
                          ->where( $colName . ' REGEXP "[[.backslash.]]"')
                          ->execute();
            foreach($rows as $row) {
                 $previous = $row->{$colName};
                 $row->{$colName} = str_replace("\\", '', $previous);
                 $row->update();
                 $i++;
                 //echo($previous . ' -> ' . $row->{$colName});
            }
        }
    }
    echo("Table {$table->name} fixed. $i fields changed." . PHP_EOL);
}
 

Documentación: