Exemple #1
0
function get_column_list($table_name)
{
    global $db;
    $res = $db->query("pragma table_info( {$table_name} )");
    return array_map(function ($row) {
        return $row['name'];
    }, sql_all($res));
}
Exemple #2
0
if (!defined('WP_DEBUG') || !WP_DEBUG) {
    return;
}
// SQL
$database = array("type" => "mysql", "host" => DB_HOST, "database" => DB_NAME, "user" => DB_USER, "pass" => DB_PASSWORD);
$pdo = new SimplePDO($database);
$tables = sql_all('SHOW TABLES', "tables_in_" . strtolower($database['database']));
foreach ($tables as $i => $table) {
    $columns = sql_all('SHOW COLUMNS FROM `' . $table . '`', "field");
    foreach ($columns as $column) {
        foreach ($changes as $source => $dest) {
            // Voir si la colonne contient la chaine recherch�e
            if (sql_first("SELECT * FROM `" . $table . "` WHERE `" . $column . "` LIKE '%" . $source . "%'")) {
                // Faire la modification complexe pour les lignes JSON
                $json = sql_all("SELECT * FROM `" . $table . "` WHERE `" . $column . "` LIKE 'a:%'");
                foreach ($json as $line) {
                    $source_j = $line->{$column};
                    $j = unserialize($line->{$column});
                    if ($j) {
                        $j = recursive_array_replace($source, $dest, $j);
                        $j = serialize($j);
                        sql_pexecute("UPDATE `" . $table . "` SET `" . $column . "`=? WHERE `" . $column . "`=?", array($j, $source_j));
                    }
                }
                // Faire ensuite la modification pour les autres lignes.
                sql_execute("UPDATE `" . $table . "` SET `" . $column . "` = replace(`" . $column . "`, '" . $source . "', '" . $dest . "') WHERE `" . $column . "` NOT LIKE 'a:%' AND `" . $column . "` LIKE '%" . $source . "%'");
            }
        }
    }
}