Skip to content

Instantly share code, notes, and snippets.

@koras
Last active April 17, 2022 13:30
Show Gist options
  • Save koras/3a1ade9deef76a4585ee5cba67802d42 to your computer and use it in GitHub Desktop.
Save koras/3a1ade9deef76a4585ee5cba67802d42 to your computer and use it in GitHub Desktop.
Удаление куска кода из таблицы в базе
<?php
// mysql -u root -p autoruk < j25_content.sql
$servername = "localhost";
$database = "";
$username = "";
$password = "";
// Создаем соединение
$link = mysqli_connect($servername, $username, $password, $database);
// Проверяем соединение
if (!$link) {
die("Connection failed: " . mysqli_connect_error());
}else{
$sql = 'select * from `j25_content` where `fulltext` LIKE \'%id="imagePreviewSrc" %\'';
$result = mysqli_query($link, $sql);
mysqli_set_charset($link,"utf8");
if ($result == false) {
print("Произошла ошибка при выполнении запроса");
}
else {
$result = mysqli_query($link, $sql);
while ($row = mysqli_fetch_array($result)) {
$txt = $row['fulltext'];
$id = $row['id'];
echo $id ;
$res = preg_replace("|id=\"imagePreviewSrc\" |",'', $txt);
$update = "update `j25_content` set `fulltext` = '$res' where `id` = '$id'";
mysqli_query($link, $update);
$sql = "select * from `j25_content` where `id` = $id limit 1";
$resulttxt = mysqli_query($link, $sql);
while ($rows = mysqli_fetch_array($resulttxt)) {
echo $rows['fulltext'];
}
exit();
}
}
}
echo "Connected successfully";
mysqli_close($link);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment