PHP Classes

File: example.php

Recommend this page to a friend!
  Classes of Nemanja Avramovic   Simple MySQL dump   example.php   Download  
File: example.php
Role: Example script
Content type: text/plain
Description: Example script
Class: Simple MySQL dump
Dump a MySQL database as SQL statements
Author: By
Last change: changed example
Date: 15 years ago
Size: 1,096 bytes
 

Contents

Class file image Download
<?php
//include class
require_once('./MySQLDump.class.php');

//create new instance of MySQLDump
$backup = new MySQLDump();
 
//set drop table if exists
$backup->droptableifexists = true;

//connect to mysql server (host, user, pass, db)
$backup->connect('localhost','root','','mysql');

//if not connected, display error
if (!$backup->connected) { die('Error: '.$backup->mysql_error); }

//dump single table
$backup->dump_table('example_table');
echo
"<pre>".htmlspecialchars($backup->output."</pre>"; //we can use htmlspecialchars in case that there are some html tags in database

//dump entire db
$backup->dump();
echo
"<pre>".htmlspecialchars($backup->output."</pre>"; //we can use htmlspecialchars in case that there are some html tags in database

//dump few tables
$backup->dump_table('example_table');
$backup->dump_table('second_table', false); //set 2nd argument to false to keep previous table(s) in output stream
echo "<pre>".htmlspecialchars($backup->output."</pre>"; //we can use htmlspecialchars in case that there are some html tags in database

?>