Computing.Net > Forums > Database > create a table from a file

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

create a table from a file

Reply to Message Icon

Name: geohoffman49431
Date: August 3, 2007 at 12:45:25 Pacific
OS: XP PRO
CPU/Ram: 512 DDR 2700
Product: Generic
Comment:

Can someone tell me why the following is not working?


$query = file_get_contents("import_data.sql");
echo ($query);
$result=mysql_query($query);


import_data.sql contains the mySql commands to add tables to a database and insert some entries.

import_data.sql looks like this:


# MySQL dump
#
# Database is ported from MS Access

# Program Version 2.0.57

CREATE DATABASE IF NOT EXISTS `growthch_GROWTHCHAMBERS`;
USE `growthch_GROWTHCHAMBERS`;

#
# Table structure for table 'contact'
#

DROP TABLE IF EXISTS `contact`;

CREATE TABLE `contact` (
`id` INTEGER NOT NULL DEFAULT 0,
`name` VARCHAR(50),
`phone` VARCHAR(50),
INDEX (`id`),
PRIMARY KEY (`id`)
) TYPE=InnoDB;

[/code]



Sponsored Link
Ads by Google

Response Number 1
Name: FishMonger
Date: August 4, 2007 at 14:34:53 Pacific
Reply:

I assume you never read the documentation on how to use the mysql_query() function. The mysql_query() function doesn't do what you think.

http://us3.php.net/manual/en/functi...

I'm not sure if php has a builtin function to do this, at teast I couldn't find one on their site. You'll probably need to do a system call and pass the sql file directly to mysql.

Here's the syntax for the mysql command that you'd wrap in a system call.

=====================================================
mysql -u [username] -p [password] [database_to_restore] < [backupfile]


0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Database Forum Home


Sponsored links

Ads by Google


Results for: create a table from a file

selecting a row from a table www.computing.net/answers/dbase/selecting-a-row-from-a-table/97.html

How to create a function in MS Acce www.computing.net/answers/dbase/how-to-create-a-function-in-ms-acce/328.html

Inserting data from text file. www.computing.net/answers/dbase/inserting-data-from-text-file/58.html