Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- error_reporting(E_ALL);
- ini_set('display_errors', '1');
- $mysql_host = 'localhost';
- $mysql_username = '';
- $mysql_password = '';
- $mysql_database = '';
- $db = new PDO('mysql:dbname='.$mysql_database.';host='.$mysql_host,$mysql_username,$mysql_password);
- // works not with the following set to 0. You can comment this line as 1 is default
- $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, 1);
- function truncate_db()
- {
- global $db;
- $sql_query_1 = "
- TRUNCATE TABLE `WIZYTY`;
- TRUNCATE TABLE `ANIMALS`;
- TRUNCATE TABLE `DOCTORS`;
- TRUNCATE TABLE `CUSTOMER`
- ";
- try {
- $stmt = $db->prepare($sql_query_1);
- $stmt->execute();
- echo "Truncate action - OK";
- }
- catch (PDOException $e)
- {
- echo $e->getMessage();
- die();
- }
- }
- function import_db()
- {
- global $db;
- try
- {
- $sql_query_2 = implode(array_map(function ($v) {
- return file_get_contents($v);
- }, glob(__DIR__ . "/*.sql")));
- $qr = $db->exec($sql_query_2);
- echo "Import action - OK";
- }
- catch (PDOException $e)
- {
- echo 'Connection failed: ' . $e->getMessage();
- }
- }
- truncate_db();
- echo '<br />';
- import_db();
- $db = null;
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement