I need help with my code. I need PHP to allow me to upload tables.sql to my Database.
Here is the code I have so far:
<?php
$dbhost ='localhost';
$dbuser = 'root';
$dbpass = 'password';
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die
('Error connecting to the mysql db');
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
mysql_select_db($dbname);
?>
<html>
<head>
<title>Inserting Tables to MySQL with PHP</title>
</head>
<?php
mysql_create_db('TESTING-DATABASE'); // creates the database
mysql_select_db('TESTING-DATABASE') or die('Cannot select database');
$queryFile = 'tables.sql';
$fp = fopen($queryFile, 'r');
$query = fread($fp, filesize($queryFile));
fclose($fp);
$result = mysql_query($query);
?>
<body>
</body>
</html>
<?php mysql_close($conn); ?>
So far I can only create the Database, but the file is not uploaded. I know my code may have problems, but I can't find where. Below is what I wanted to upload:
CREATE TABLE 002_news (
id_news bigint(13) NOT NULL auto_increment,
ueberschrift varchar(250) default NULL,
kurztext longtext,
autor varchar(100) default NULL,
von date default NULL,
bis date default NULL,
langtext longtext,
bild varchar(30) default NULL,
weiter enum('Y','N') NOT NULL default 'N',
PRIMARY KEY (id_news)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
Is it possible that the ENGINE=InnoDB DEFAULT CHARSET=latin1 is the cause? Because when I take it out, the uploading works. But why would this be an issue?
Help!
Marc