FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


automatic use of .sql file





dark inca
I already posted in the dutch forum, but nobody can answer me.

Is it possible to automatic use a .sql script. So it will do all commando's inside? (I want to use it to restore a whole database)

Maybe with cron?
But i didn't find any info about it.
____________________
dark Inca
rohan2kool
I don't get your question. Either:

1. You want to run a .sql file every n number of seconds (maybe that's why you suggested cron).

2. (What i think) You want to run a .sql file like a query.

In the first case, make urself a bit more clear; as for the second, here's it:

Code:


<?php
   define('DB_USER', "root");
   define('DB_DOM', "localhost");
   define('DB_PASS', "");
   define('DB_SEL', "database1");

   //call function like:
   //runFileAsQuery($filename [, $selectdb]);
   //$filename: Name of the .sql file
   //$selectdb : If true, DB_SEL is selected
   //            If false, the .sql file must select a db


   function runFileAsQuery($filename, $selectdb = false) {
      if($filename == "") {
         return false;
      } else {
         if(!file_exists($filename)) {
            return false;
         } else {
            if(!is_readable($filename)) {
               return false;
            } else {
               $fhandle = fopen($filename, "rb");
               $query = "";

               $query = fread($fhandle, filesize($filename));

               //For SQL Injection safety
               $query = mysql_escape_string($query);

               $conn = @ mysql_connect(DB_DOM, DB_USER, DB_PASS);

               if(!$conn) {
                  return false;
               } else {
                  if($selectdb) {
                     $rs = @ mysql_select_db(DB_SEL, $conn);
                  }

                  $rs = @ mysql_query($query);

                  return $rs;
               }
            }
         }
      }
   }
?>



I haven't tried this, but it most probably should work. Here, just change the definitions of DB_USER, DB_PASS and DB_DOM to the username, password and domain on your system's MySQL installation.

Rest all is self explainatory.

rohan
dark inca
I want to put up some demo forums.
But if a spammer or a hacker tries to ****** up the demo forums, it will be for a short period, because each X houres the database restores itselfs. So spam will be delete and most hacks don't edit youre files but database templates. So that will be restored to.

So i made a backup from the database and the .sql file must be run as a query each X houres.

Youre php file will do this once, but is it possible to do this each X houres automatic.

____________________
Dark Inca
rohan2kool
ok.. i don't mean to be rude, but that is not something wise enough to do. anyways... i'd like to help.

Basically, what you need to do is make a file that does the restoring/backing every time it is run and then run it on a timely basis. I won't be making the file coz maknig the backup is a pretty complex script. Most probably one of your forum softwares' include file might be having the function to do so. Let's say the file is 'restoredb.php' and is located at: http://mysite.com/restoredb.php

Then, move to your cpanel account, and then select 'Cron Jobs'. Once there, select 'Advanced (Unix Style)'. Let's say you want it to run every 3 hours. Set ur cron to:

Minute: *
Hour: 0,3,6,9,12,15,18,21
Day: *
Month: *
Year: *
Command: lynx --dump http://mysite.com/restoredb.php

maybe that's of some help to you,
rohan
Related topics
script backup database
SLOW UPLOADING AN SQL FILE
Executing a .sql file through PHP
making sql dump wit php
problem in uploading database file
How to edit SQL files?
.sql problem
Importing/executing a BIG .SQL File
Issue uploading SQL database.
How do i execute an sql file in a php script?
Oracle SQL
SQL Injection
LARGE MYSQL FILE : Need HELP
php sql import
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.