Hey guys & gals.
I'm trying to finish my install script. I'm almost there. The only thing left is the SQL script. I have it so far to open and read the contents of the sql script. That was easy.
So I take the contents (which are fully read), and I use them as so:
$fp = fopen("table.sql", "r");
$contents = fread($fp, filesize("table.sql"));
fclose($fp);
$result = mysql_query($contents);
if(!$result){
echo '<p>There is something wrong with the query. Here is what it tried to run:<hr />'.$contents.'</p>';
}
else{
echo '<p>Database is setup, now let us continue...<br /><a href="'.$self.'?step=6"><button>Continue ==></button></a></p>';
}
When I bring up this script in my browser, it reads the contents of table.sql fine, but I can't seem to get it to fire off as a query.
The SQL File would look like any normal SQL file without PHP markup. So as an example:
--
-- Table structure for table `tickets_categories`
--
CREATE TABLE `categories` (
`categories_id` tinyint(3) unsigned NOT NULL auto_increment,
`categories_name` varchar(20) NOT NULL default '',
`categories_order` tinyint(3) unsigned NOT NULL default '1',
PRIMARY KEY (`categories_id`),
UNIQUE KEY `categories_name` (`categories_name`),
KEY `categories_order` (`categories_order`)
) TYPE=MyISAM AUTO_INCREMENT=3 ;
--
-- Dumping data for table `categories`
--
INSERT INTO `categories` VALUES (1, 'Department 1', 1);
INSERT INTO `categories` VALUES (2, 'Department 2', 2);
So that is an example of what my SQL file looks like. Works great if I go through phpMyAdmin, but not if I go through PHP...
I have even tried making the contents of the SQL file the code that is output for PHP by phpMyAdmin...
A little guidance here would be great.
Thanks.
~Brett