fordev22.com
  • Home
  • สอนทำระบบ POS (Point of Sale)
  • Flutter สำหรับผู้เริ่มต้น
  • PHP+MySqli
  • เนื้อหาอื่น ๆ
    • สอน Bootstrap 5
    • Dreamweaver+Bootstrap+PHP
    • Dreamweaver
    • Computer Tip
  • ABOUT US
    • Personal information
    • บริการ
    • ผลงาน
    • ตัวอย่าง ผลงานด้านการสอน (สอนสดผ่าน Google Meet, Zoom)
  • Search

(2023) PHP+MySqli EP.40 How to Backup MySQL Database using PHP

April 10, 2023/in PHP+MySqli /by fordev22

(2023) PHP+MySqli EP.40
How to Backup MySQL Database
using PHP

 

 

 


ระบบบริหารจัดการ ศูนย์ซ่อมรถยนต์ Car Service System ( PHP 7++ ขึ้นไป )

 

ตัวอย่างผลงาน FD22 Logistic 2020 ระบบบริหารจัดการขนส่ง

ระบบ บริหารจัดการร้านกาแฟ PHP | FD22-Cafe (Coffee AND Bakery)

CART&POS (ระบบจัดการงานขายหน้าร้านและ ออนไลน์ สำหรับร้านค้าขนาดกลาง,SME

เว็บไซต์ จองคิวทำเล็บ MANICURE SYSTEM ( PHP 7++ ขึ้นไป )

(2023) PHP+MySqli EP.40 How to Backup MySQL Database using PHP

Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
 
// Database configuration
$host = "localhost";
$username = "fordev22";
$password = "fordev22";
$database_name = "fordev22";
 
// Get connection object and set the charset
$conn = mysqli_connect($host, $username, $password, $database_name);
$conn->set_charset("utf8");
 
 
// Get All Table Names From the Database
$tables = array();
$sql = "SHOW TABLES";
$result = mysqli_query($conn, $sql);
 
while ($row = mysqli_fetch_row($result)) {
    $tables[] = $row[0];
}
 
$sqlScript = "";
foreach ($tables as $table) {
    
    // Prepare SQLscript for creating table structure
    $query = "SHOW CREATE TABLE $table";
    $result = mysqli_query($conn, $query);
    $row = mysqli_fetch_row($result);
    
    $sqlScript .= "\n\n" . $row[1] . ";\n\n";
    
    
    $query = "SELECT * FROM $table";
    $result = mysqli_query($conn, $query);
    
    $columnCount = mysqli_num_fields($result);
    
    // Prepare SQLscript for dumping data for each table
    for ($i = 0; $i < $columnCount; $i ++) {
        while ($row = mysqli_fetch_row($result)) {
            $sqlScript .= "INSERT INTO $table VALUES(";
            for ($j = 0; $j < $columnCount; $j ++) {
                $row[$j] = $row[$j];
                
                if (isset($row[$j])) {
                    $sqlScript .= '"' . $row[$j] . '"';
                } else {
                    $sqlScript .= '""';
                }
                if ($j < ($columnCount - 1)) {
                    $sqlScript .= ',';
                }
            }
            $sqlScript .= ");\n";
        }
    }
    
    $sqlScript .= "\n";
}
 
if(!empty($sqlScript))
{
    // Save the SQL script to a backup file
    $backup_file_name = $database_name . '_backup_' . time() . '.sql';
    $fileHandler = fopen($backup_file_name, 'w+');
    $number_of_lines = fwrite($fileHandler, $sqlScript);
    fclose($fileHandler);
 
    // Download the SQL backup file to the browser
    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename=' . basename($backup_file_name));
    header('Content-Transfer-Encoding: binary');
    header('Expires: 0');
    header('Cache-Control: must-revalidate');
    header('Pragma: public');
    header('Content-Length: ' . filesize($backup_file_name));
    ob_clean();
    flush();
    readfile($backup_file_name);
    exec('rm ' . $backup_file_name);
}
?>

 

 

Facebook
Twitter
Line
Tags: php, php+sqli php+sqli, Point of Sale Point of SalePOS POS, POS System POS System, ฟรีโปรเจคนักศึกษา, ฟอร์ม php, รับพัฒนาระบบ รับพัฒนาระบบ, รับเขียนโปรแกรม รับเขียนโปรแกรม, สอน bootstrap, สอน php, สอน php mysql, สอน php mysqli, สอน php พื้นฐาน, สอน php เบื้องต้น, สอนทำเว็บ, สอนทำเว็บ สอนทำเว็บ, สอนพัฒนาระบบ สอนพัฒนาระบบ, สอนเขียนเว็บ, สอนเขียนเว็บ สอนเขียนเว็บ, สอนเขียนโปรแกรม สอนเขียนโปรแกรม, เขียนโปรแกรมราคาถูก เขียนโปรแกรมราคาถูก, แจกระบบ php, แจกโคด php, โปรเจคคอมธุ, โปรเจคคอมพิวเตอร์, โปรเจคคอมพิวเตอร์ธุรกิจ, โปรเจคจบ คอมพิวเตอร์, โปรเจคนักศึกษา, โปรเจควิทยาการคอม Share this entry
Share this entry
  • Share on Facebook
  • Share on Twitter
  • Share on Google+
  • Share on Pinterest
  • Share on Linkedin
  • Share on Tumblr
  • Share on Vk
  • Share on Reddit
  • Share by Mail
https://fordev22.com/wp-content/uploads/2018/10/phpsqli.png 720 970 fordev22 https://fordev22.com/wp-content/uploads/2018/08/logo_fordev22_2.png fordev222023-04-10 22:53:142023-04-12 11:18:44(2023) PHP+MySqli EP.40 How to Backup MySQL Database using PHP
You might also like
สอนทำระบบ POS (ระบบขายหน้าร้าน) Ep 29. บันทึกการสั่งซื้อเข้าตาราง Order (บันทึกการสั่งซื้อ Part 1)
Bootstrap EP.27 การแสดงข้อมูล 2 ตาราง โดยอิงจาก id ในตารางแรก (INNER JOIN)
Dreamweaver EP.4 โปรแกรมเพิ่มข้อมูลโดยใช้ Dreamweaver CS6
Dreamweaver EP.5 โปรแกรมแก้ไขข้อมูลโดยใช้ Dreamweaver CS6
Bootstrap EP.2 จัดการกับ navbar ให้เหมาะสม
สอนทำระบบ POS (ระบบขายหน้าร้าน) Ep 38. สร้างไฟล์ orderdetail(บันทึกการสั่งซื้อ Part 10)
PHP+MySqli EP.34 Convert Date Picker พ.ศ.To ค.ศ. (โดยใช้ functions explode ต่อจาก EP.33)
สอนทำระบบ POS (ระบบขายหน้าร้าน) Ep 49. ติดตั้ง Library mPDF เพื่อเตรียมออกรายงาน (PDF Part 1)

บริการและผลงาน

  • Home
  • Personal Information
  • คอสเรียนที่เปิดอยู่
  • ตัวอย่าง ผลงานด้านการสอน (สอนสดผ่าน Google Meet, Zoom)
  • บริการ
  • ผลงาน

ช่องทางการติดต่อ

Tel. 090-959-1107

ID Line. fordza4you

E-mail. fordza4you@gmail.com


รับพัฒนาระบบ
รับพัฒนาเว็บแอพพลิเคชั่น
รับพัฒนาเว็บไซต์

Page

Popular
  • (2025) สอน ใช้งาน Telegram Bot API เพื่อการแจ้งแตือนข้อความ...February 28, 2025 - 10:48 pm
  • Computer Tip EP.2 การปรับเสียง...October 13, 2016 - 10:13 pm
  • Dreamweaver EP.1 ลงโปรแกรมจำลอง...October 15, 2016 - 9:28 pm
  • Dreamweaver EP.2 สร้าง Database ด้วย ...October 16, 2016 - 12:48 pm
  • Dreamweaver EP.3 การสร้างที่เก็บเว็บไซต์และสร้าง...October 16, 2016 - 6:33 pm
Recent
  • (2025) สอน ใช้งาน Telegram Bot API เพื่อการแจ้งแตือนข้อความ...February 28, 2025 - 10:48 pm
  • (2025) สอน ใช้งาน Telegram Bot API เพื่อการแจ้งแตือนข้อความ...February 22, 2025 - 1:39 pm
  • (2025) สอน ใช้งาน Telegram Bot API เพื่อการแจ้งแตือนข้อความ...February 21, 2025 - 10:19 pm
  • (2025) สอน ใช้งาน Telegram Bot API เพื่อการแจ้งแตือนข้อความ...February 20, 2025 - 4:21 pm
  • สอน Flutter Ep 4. ติดตั้ง SDK Simulator...June 7, 2023 - 1:54 pm
Comments
  • sssssMay 4, 2017 - 11:52 am by fordev22
  • sssssMay 4, 2017 - 11:50 am by fordev22
  • Awaiting BACS payment Order status changed from Pending...March 1, 2017 - 9:23 am by WooCommerce
Tags
Bootstrap Database Datatable Datatable Serverside Dreamweaver Flutter beginner course Flutter coding for beginners Flutter tutorial Learn Flutter php php+sqli php+sqli php+sqli Point of Sale Point of SalePOS POS POS System POS System showe Sqli sqli xampp กับ dreamweaver ฟรีโปรเจคนักศึกษา ฟอร์ม php รับพัฒนาระบบ รับพัฒนาระบบ รับเขียนโปรแกรม รับเขียนโปรแกรม สอน bootstrap สอน php สอน php mysql สอน php mysqli สอน php พื้นฐาน สอน php เบื้องต้น สอนทำเว็บ สอนทำเว็บ สอนทำเว็บ สอนพัฒนาระบบ สอนพัฒนาระบบ สอนเขียนเว็บ สอนเขียนเว็บ สอนเขียนเว็บ สอนเขียนโปรแกรม สอนเขียนโปรแกรม เขียนโปรแกรมราคาถูก เขียนโปรแกรมราคาถูก เพิ่มข้อมูล แจกระบบ php แจกโคด php โปรเจคคอมธุ โปรเจคคอมพิวเตอร์ โปรเจคคอมพิวเตอร์ธุรกิจ โปรเจคจบ คอมพิวเตอร์ โปรเจคนักศึกษา โปรเจควิทยาการคอม โปรเจควิทยาการคอม Share this entry โปรเจควิทยาการคอม Share this entry Share this entry

Copyright@2018.fordev22.com

สอนทำระบบ POS (ระบบขายหน้าร้าน)... (2023) PHP+MySqli EP.41 How to AJAX CrudPHP MySqli (Part 1 insert AND view...
Scroll to top