Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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]

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]

![]() |
![]() |
![]() |

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