![]() |
restore db table
Any one who can help with php scripts (step by step) for restoring a table in mysql database
|
Has the previous table been saved somewhere ... like you did a backup at one time?
Or are you not concerned about the table values ... just the table column names, etc? |
Quote:
Any Idea please. |
So you know where that backup is located? You can see the file?
If so, how did you back it up? What did your PHP script do to make the backup? Is it a text file, an XML file, a query file? |
Quote:
<?php backup_tables('localhost','root','','dsm_db'); /* backup the db OR just a table */ function backup_tables($host,$user,$pass,$name,$tables = 'student_info') { $link = mysql_connect($host,$user,$pass); mysql_select_db($name,$link); //get all of the tables if($tables == '*') { $tables = array(); $result = mysql_query('SHOW TABLES'); while($row = mysql_fetch_row($result)) { $tables[] = $row[0]; } } else { $tables = is_array($tables) ? $tables : explode(',',$tables); } //cycle through foreach($tables as $table) { $result = mysql_query('SELECT * FROM '.$table); $num_fields = mysql_num_fields($result); $return.= 'DROP TABLE '.$table.';'; $row2 = mysql_fetch_row(mysql_query('SHOW CREATE TABLE '.$table)); $return.= "\n\n".$row2[1].";\n\n"; for ($i = 0; $i < $num_fields; $i++) { while($row = mysql_fetch_row($result)) { $return.= 'INSERT INTO '.$table.' VALUES('; for($j=0; $j<$num_fields; $j++) { $row[$j] = addslashes($row[$j]); $row[$j] = ereg_replace("\n","\\n",$row[$j]); if (isset($row[$j])) { $return.= '"'.$row[$j].'"' ; } else { $return.= '""'; } if ($j<($num_fields-1)) { $return.= ','; } } $return.= ");\n"; } } $return.="\n\n\n"; } //save file $handle = tais.date("_d.m.Y").'.sql'; ob_clean(); ob_start(); Header("Content-type: application/octet-stream"); Header("Content-Disposition: attachment; filename=$handle"); //echo $result; echo $return; ob_end_flush(); exit; } ?> |
So you have a file on your PC with the .sql file extension.
That file was created by your PHP script, it spit-out the .sql content, and you saved it on your PC. Now you want to go in reverse ... you want to take that .sql file and restore the database ... is that correct? I'm just trying to follow what you mean by "restore db table". We might both be thinking of two different things. If what I'm thinking is correct, you need to have access to "phpMyAdmin". This is usually done using your webhost (website) control panel. They have a thing in the control panel called "phpMyAdmin" where you can access all of your mysql databases, view them, edit them, add/delete. You can also present it with an .sql file ... like the one you saved as a backup. It will execute that .sql file and perform the query instructions to restore your table(s). . |
Quote:
I am very familiar with phpMyadmin and that my web host company provides that platform. The problem I found with that is, I have a given a limitation of importing only 10.2Mb of data from phpMyadmin. At this moment I have only 55Mb of data for the whole database and I frequently upload and download one table of size 9Mb though I zip it and get 1-2 Mb, but am sure it come a time where I will be required to import say 100Mb. Therefore If I have the script in the application it will be easier to do so. And that is why I asking for script of restore table back to the database, cause I have the script for taking backup from database. This is a link to the login page of that application: http://tais.teku.ac.tz |
Quote:
|
Quote:
Would you please provide me with php scripts to such task (restoring table to the mysql db)! |
| All times are GMT +1. The time now is 03:14 AM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.