Loading SQL files (not CSV) into mySQL
| From: | Andy Warwick | Date: | Tue, 03 Apr 2001 23:35:34 +0000 |
| Subject: | Loading SQL files (not CSV) into mySQL | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-46912@lists.php.net to get a copy of this message | ||
I'm after some pointers on how to dump and load SQL files to and from mySQL
using a PHP/HTML form.
I've read the manual about "LOAD DATA INFILE", but as far as I can tell that
won't help in this case. Unfortunately, CSV files are not an option
(client's demands... go figure).
What I'm after is dumping/uploading SQL files of the form:
==========================================================
#
# PHP/MySQL Demo - Table Dump
# --------------------------------------------------------
#
# Structure
#
DROP TABLE IF EXISTS demo;
CREATE TABLE demo (
id tinyint(2) unsigned zerofill NOT NULL auto_increment,
name char(50) NOT NULL,
logo_url char(50) NOT NULL,
page_colour char(6) DEFAULT 'FFFFFF' NOT NULL,
last_order datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
PRIMARY KEY (id),
KEY id (id),
UNIQUE id_2 (id)
);
#
# Data
#
INSERT INTO demo (id, name, logo_url, page_colour, last_order) VALUES (
'01', 'CompanyName', 'logo.gif', '99CCFF', '2001-04-06
13:21:31');
==========================================================
Complete with table creation and data inserts. In effect, it needs to be
standalone text files full of SQL commands.
I know it can be done, because phpMyAdmin has exactly this facility. But
even after studying the code of that carefully, I can't tell which specific
pieces are handling this enough to extract the facility.
Can anyone point me, or is willing to donate, any articles/code snippets/etc
that will help.
TIA
Andy Warwick