PHP den SQL indirmeyi nasil yapabilirim ?
12
●266
- 29-01-2025, 23:05:37m4lisen adlı üyeden alıntı: mesajı görüntüle
- 29-01-2025, 23:06:05eryfyzllh adlı üyeden alıntı: mesajı görüntüle
https://rustdesk.com/ - 29-01-2025, 23:09:16php kodlarına erişim sağlıyor musunuz?
Kodlara erişim sağlıyor iseniz vertabanı baglantı kullanıcı adı şifre ye ulaşabilirsiniz.
buradal select all yaparak tablo ve verilee ulaşım sağlarsınız - 29-01-2025, 23:09:33ticaretime güvenip ftp iletirseniz bakabilirim hocam
05457231273 whatsapptan yazabilirsiniz - 29-01-2025, 23:12:29
<!DOCTYPE html> <html lang="tr"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Veritabanı Yedekleme</title> <style> body { font-family: Arial, sans-serif; background-color: #f4f4f9; display: flex; justify-content: center; align-items: center; height: 100vh; margin: 0; } .container { background-color: #fff; padding: 20px; border-radius: 8px; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); text-align: center; } h1 { color: #333; margin-bottom: 20px; } .backup-button { background-color: #28a745; color: white; border: none; padding: 10px 20px; border-radius: 5px; font-size: 16px; cursor: pointer; transition: background-color 0.3s ease; } .backup-button:hover { background-color: #218838; } .backup-button:active { background-color: #1e7e34; } .message { margin-top: 20px; color: #333; font-size: 14px; } </style> </head> <body> <div class="container"> <h1>Veritabanı Yedekleme</h1> <form method="post"> <button type="submit" name="backup" class="backup-button">Yedek Al</button> </form> <div class="message"> <?php if (isset($_POST['backup'])) { // Veritabanı Bağlantı Bilgileri $host = 'localhost'; $user = 'kullanici_adi'; $password = 'parola'; $database = 'veritabani_adi'; // Yedek dosyası ismi $backup_file = $database . '_' . date('Y-m-d_H-i-s') . '.sql'; // Veritabanına bağlan $conn = mysqli_connect($host, $user, $password, $database); // Bağlantı kontrolü if (!$conn) { die("Veritabanı bağlantısı başarısız: " . mysqli_connect_error()); } // Tabloları al $tables = array(); $result = mysqli_query($conn, "SHOW TABLES"); while ($row = mysqli_fetch_row($result)) { $tables[] = $row[0]; } // Yedek içeriğini oluştur $content = ""; foreach ($tables as $table) { // Tablo yapısını al $result = mysqli_query($conn, "SHOW CREATE TABLE $table"); $row = mysqli_fetch_row($result); $content .= "\n\n" . $row[1] . ";\n\n"; // Tablo verilerini al $result = mysqli_query($conn, "SELECT * FROM $table"); $num_fields = mysqli_num_fields($result); while ($row = mysqli_fetch_row($result)) { $content .= "INSERT INTO $table VALUES("; for ($i = 0; $i < $num_fields; $i++) { $row[$i] = addslashes($row[$i]); $row[$i] = str_replace("\n", "\\n", $row[$i]); if (isset($row[$i])) { $content .= '"' . $row[$i] . '"'; } else { $content .= 'NULL'; } if ($i < ($num_fields - 1)) { $content .= ','; } } $content .= ");\n"; } $content .= "\n"; } // Yedek dosyasını kaydet $handle = fopen($backup_file, 'w+'); fwrite($handle, $content); fclose($handle); // Yedek dosyasını indir header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename=' . basename($backup_file)); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate'); header('Pragma: public'); header('Content-Length: ' . filesize($backup_file)); readfile($backup_file); // Dosyayı sunucudan sil (isteğe bağlı) unlink($backup_file); // Bağlantıyı kapat mysqli_close($conn); echo "Yedekleme başarıyla tamamlandı ve dosya indirildi."; } ?> </div> </div> </body> </html>
- 29-01-2025, 23:12:54SQL bilgilerini forma gir backups dizinine dbyi yedek alır.
<?php class DatabaseBackup { private $host; private $username; private $password; private $database; private $conn; public function __construct($host, $username, $password, $database) { $this->host = $host; $this->username = $username; $this->password = $password; $this->database = $database; } public function connect() { try { $this->conn = new mysqli($this->host, $this->username, $this->password, $this->database); if ($this->conn->connect_error) { throw new Exception("Bağlantı hatası: " . $this->conn->connect_error); } $this->conn->set_charset("utf8"); return true; } catch (Exception $e) { die("Hata: " . $e->getMessage()); } } public function backup() { try { $this->connect(); $tables = array(); $result = $this->conn->query("SHOW TABLES"); while ($row = $result->fetch_row()) { $tables[] = $row[0]; } $sqlScript = ""; // SQL başlangıç bilgileri $sqlScript .= "-- Database Backup\n"; $sqlScript .= "-- Oluşturulma Tarihi: " . date("Y-m-d H:i:s") . "\n"; $sqlScript .= "-- Sunucu versiyonu: " . $this->conn->server_info . "\n"; $sqlScript .= "-- PHP Versiyonu: " . phpversion() . "\n\n"; $sqlScript .= "SET FOREIGN_KEY_CHECKS=0;\n"; $sqlScript .= "SET SQL_MODE = \"NO_AUTO_VALUE_ON_ZERO\";\n"; $sqlScript .= "SET AUTOCOMMIT = 0;\n"; $sqlScript .= "START TRANSACTION;\n"; $sqlScript .= "SET time_zone = \"+00:00\";\n\n"; foreach ($tables as $table) { // Tabloyu temizleme komutu $sqlScript .= "\nDROP TABLE IF EXISTS `" . $table . "`;\n"; // Tablo yapısını al $query = "SHOW CREATE TABLE " . $table; $result = $this->conn->query($query); $row = $result->fetch_row(); $sqlScript .= $row[1] . ";\n\n"; // Tablo verilerini al $query = "SELECT * FROM " . $table; $result = $this->conn->query($query); if ($result->num_rows > 0) { $sqlScript .= "INSERT INTO `" . $table . "` VALUES"; $first_row = true; while ($row = $result->fetch_assoc()) { if (!$first_row) { $sqlScript .= ","; } else { $first_row = false; } $sqlScript .= "\n("; foreach ($row as $value) { if ($value === null) { $sqlScript .= "NULL,"; } else { $sqlScript .= "'" . $this->conn->real_escape_string($value) . "',"; } } $sqlScript = rtrim($sqlScript, ","); $sqlScript .= ")"; } $sqlScript .= ";\n"; } } $sqlScript .= "\nSET FOREIGN_KEY_CHECKS=1;\n"; $sqlScript .= "COMMIT;\n"; if (!empty($sqlScript)) { // Dosya adını oluştur $backupFileName = $this->database . '_backup_' . date('Y-m-d_H-i-s') . '.sql'; // Dosyayı kaydet $backup_folder = "backups/"; if (!file_exists($backup_folder)) { mkdir($backup_folder, 0777, true); } $file_path = $backup_folder . $backupFileName; file_put_contents($file_path, $sqlScript); echo "<div style='background-color: #dff0d8; color: #3c763d; padding: 15px; margin: 10px 0; border-radius: 4px;'>"; echo "Yedekleme başarıyla tamamlandı!<br>"; echo "Dosya adı: " . $backupFileName . "<br>"; echo "Dosya yolu: " . $file_path; echo "</div>"; } } catch (Exception $e) { die("Yedekleme hatası: " . $e->getMessage()); } } } // Kullanım örneği: if ($_SERVER["REQUEST_METHOD"] == "POST") { $host = $_POST['host']; $username = $_POST['username']; $password = $_POST['password']; $database = $_POST['database']; $backup = new DatabaseBackup($host, $username, $password, $database); $backup->backup(); } ?> <!-- HTML Form --> <!DOCTYPE html> <html> <head> <title>Veritabanı Yedekleme</title> <meta charset="utf-8"> <style> body { font-family: Arial, sans-serif; margin: 40px; } .container { max-width: 500px; margin: 0 auto; } .form-group { margin-bottom: 15px; } label { display: block; margin-bottom: 5px; } input[type="text"], input[type="password"] { width: 100%; padding: 8px; border: 1px solid #ddd; border-radius: 4px; } button { background-color: #4CAF50; color: white; padding: 10px 15px; border: none; border-radius: 4px; cursor: pointer; } button:hover { background-color: #45a049; } </style> </head> <body> <div class="container"> <h2>Veritabanı Yedekleme</h2> <form method="POST"> <div class="form-group"> <label>Host:</label> <input type="text" name="host" required> </div> <div class="form-group"> <label>Kullanıcı Adı:</label> <input type="text" name="username" required> </div> <div class="form-group"> <label>Şifre:</label> <input type="password" name="password" required> </div> <div class="form-group"> <label>Veritabanı Adı:</label> <input type="text" name="database" required> </div> <button type="submit">Yedekle</button> </form> </div> </body> </html>