473,748 Members | 2,625 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

run mysql dump code via a form

107 New Member
I want to run the mysql generated dump values of a database through a textarea in php. I am copying the whole dump code in a textarea and then let the php run the entire code. But here the problem is that the unwanted tags or lines like the mysql comments needs to be ignored and only the actual sql queries should run. How do i do it?

May be this is not very clear. Well, i have a database which needs to be updated in every 3 or 6 months for which the actual data is collected from another source in excel format. I convert this excel data into mysql format in my local machine and then the data needs to be updated in my ISP's server for which i am creating a form through which the updates can be done. I want the updates to be done online without myself having to go to my ISP. So in this case phpmyadmin generates me the mysqldump sql file but when i copy and run the whole contents of the file, it has commented tags which php donot ignore. It runs along with the commented tags as a result the database is never updated. I want a solution to ignore the commented tags so that php runs only the genuine sql queries.
Jun 19 '09 #1
1 2683
Atli
5,058 Recognized Expert Expert
You could save the entire thing to a temporary file on the server and import it through exec.

Like:
Expand|Select|Wrap|Line Numbers
  1. if(file_put_contents($tempFile, $_POST['dump'])) 
  2. {
  3.     exec("mysql --user={$mysqlUser} --password={$mysqlPass} {$targetDatabase} < {$tempFile}", $out, $failed);
  4.  
  5.     if($failed) {
  6.         echo "Import failed!";
  7.     }
  8.     else {
  9.         echo "Your backup has been successfully imported!";
  10.     }
  11.  
  12.     // Delete the dump file
  13.     unlink($tempFile);
  14. }
Some hosts might not allow the use of exec, but it's worth a try.
Jun 19 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
23641
by: Michel Feldheim | last post by:
Hi everybody, I have some big csv-like files with 15.000 and more artikles stored in it. They should be put into a mysql database. I thought about PHP processing but only the read and print of these lines using the read_csv() function as in the attached script has a more-minutes execution time. What would be the better solution.. a Visual Basic written import tool that uses ODCB or a PHP using one?
4
2574
by: Dave Moore | last post by:
Hi All, I'm looking at using PHP and MySQL for a particular website application. However, I was a bit concerned that if a PHP script went wrong then it would be possible to accidentally delete or overwrite large chunks of the data in the database which presumably would then be lost. What is the usual procedure for these situations?. Is it possible to back up a database somehow so that data from a previous time can be retrieved?. Ta,...
0
1285
by: Dyego Souza do Carmo | last post by:
Hi, I'd found a bug when I'd tried to use blob fields and innoDb. To see the bug, do the follow: *) Create a database. *) Import the dump file that is attached to this e-mail. (cfgimpressao.dump) *) Use the following commands:
0
3527
by: Lenz Grimmer | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi, MySQL 4.0.14, a new version of the popular Open Source/Free Software Database, has been released. It is now available in source and binary form for a number of platforms from our download pages at http://www.mysql.com/downloads/ and mirror sites.
6
14510
by: Daniel Gwynne | last post by:
I am trying to read a mysql dump file that I was given from a mysql dump file into my mysql server, I am using the following command at the mysql command line and get the following error: mysql> items < c:\bookings\items.mtsql ERROR: Unknown command '\b'. ERROR: Unknown command '\i'. Does anyone know what this means?
2
2808
by: Dudu | last post by:
Dear Programmers I try to install mysql version 5.0 and I encountered with a problem when I tried to start the service. I got error 1067. I checked the log file and saw the following records (which doesn't tell anything to me): 060527 12:46:54 InnoDB: Database was not shut down normally! InnoDB: Starting crash recovery. InnoDB: Reading tablespace information from the .ibd files...
7
3772
by: Ivan Marsh | last post by:
Hey Folks, I'm having a heck of a time wrapping mind around AJAX. Anyone know of a simple, straight-forward example for pulling a simple query from mysql with PHP using AJAX? As I understand it I need a PHP script that pulls the query and dumps the data into XML format, that is called by triggering a javascript event that reads that file with XMLhttprequest.
10
13412
by: eholz1 | last post by:
Hello Members, I am setting up a photo website. I have decided to use PHP and MySQL. I can load jpeg files into the table (medium blob, or even longtext) and get the image(s) to display without a problem. I am using chunk_split(data) and the base64_encode and base64_decode on the files. I do a select from the database, and then echo the image (with header(Content Type: image/jpeg) and the decoded image displays fine. Yes, I have...
6
1634
by: blitzztriger | last post by:
Hello all! This might be simple,but im having some problems in parsing the php code, can someone help? i have a text file with this (for example): -------------------------------------------------------------------- blitzztriger - time : 1 hello - ( 47) 52 40 30,000 (+600) 50% 20,000 (+400) 50%
0
8995
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8832
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9561
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9381
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9332
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6078
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4608
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3316
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.