Hey there everybody!
Me and a couple of others are currently making a CMS but we got a problem :(

Here is the code:

function ImportSQL()
	{
		$conn = mysql_connect($_POST['host'] . ":" . $_POST['port'], $_POST['user'], $_POST['pass']);
		mysql_select_db($_POST['vision_db'], $conn);
		$db_content = @file_get_contents("../sql/Database.sql");
		$query = mysql_query($db_content);
		if(!$query){
			return mysql_error();
		}else{
			return true;
		}
	}

and here is the error:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'CREATE TABLE `navigation` ( `id` int(11) NOT NULL AUTO_INCREMENT, `url` te' at line 2

i hope to get an answer! TY :D

Dani AI

Generated

Main cause: the install dump contains many SQL statements (DROP/CREATE/INSERT). Passing the whole file string into the old mysql_query call causes the server to see a second statement (CREATE ...) and return a syntax error — the ext/mysql API does not execute multiple statements in a single mysql_query call. Also note that 's "SOURCE" idea is a mysql client command, not valid SQL for mysql_query or mysqli_query, so it will not work inside PHP.

Practical fixes and checks tied to the thread posts ( asked for the dump and posted it):

  • Remove the error-suppression operator when debugging so file_read errors show (file_get_contents returning false will silently break the flow).
  • Verify the file path and filesystem permissions and check for a UTF-8 BOM at the start of the dump (a BOM can introduce weird characters and trigger a syntax error before the first statement).
  • Confirm the MySQL user has CREATE/ALTER privileges for the target database.

A reliable PHP solution is to use mysqli_multi_query (or PDO) to run the full dump in one go. Example pattern:

$mysqli = new mysqli($host, $user, $pass, $db, $port);
$sql = file_get_contents('path/to/Database.sql');
if ($mysqli->multi_query($sql)) {
  do {
    if ($res = $mysqli->store_result()) { $res->free(); }
  } while ($mysqli->more_results() && $mysqli->next_result());
} else {
  echo $mysqli->error;
}

Alternatives: import from the shell with the mysql client (recommended for large dumps):

mysql -h host -P port -u user -p database_name < /path/to/Database.sql

Cautions: if the dump contains DELIMITER blocks or stored routines, the client import is safer; splitting the file by simple semicolons can break on quoted strings or procedure bodies. For long-term stability, migrate away from the deprecated ext/mysql to mysqli or PDO.

Recommended Answers

All 3 Replies

can you shoe us the code on database.sql

/*
VisionCMS - Database
---
This file is used by the install script. So do not delete!
*/
DROP TABLE IF EXISTS `navigation`;
CREATE TABLE `navigation` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `url` text NOT NULL,
  `title` varchar(10) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=4 DEFAULT CHARSET=latin1;

DROP TABLE IF EXISTS `pages`;
CREATE TABLE `pages` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `title` text NOT NULL,
  `content` text NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

DROP TABLE IF EXISTS `settings`;
CREATE TABLE `settings` (
  `id` int(11) NOT NULL,
  `title` text NOT NULL,
  `website` text NOT NULL,
  `servername` text NOT NULL,
  `core` text NOT NULL,
  `template` text NOT NULL,
  `admin_gmlevel` int(2) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=latin1;

DROP TABLE IF EXISTS `news`;
CREATE TABLE `news` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `title` text NOT NULL,
  `content` text NOT NULL,
  `author` text NOT NULL,
  `date` text NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

DROP TABLE IF EXISTS `shoutbox`;
CREATE TABLE `shoutbox` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `msg` text NOT NULL,
  `author` text NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

there you go

Omg use google, this is a broadly discussed topic.

if (mysql_query("SOURCE file.sql"))
{
  echo "success";
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.