Jumba Posted April 10, 2007 Share Posted April 10, 2007 Hi guys, I got this PHP Script to read .sql files and execute the queries in the database but I get this 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 'Resource id #1' at line 1" You can see it here http://lnl.yurx.com/insert.php But when I add the .sql file in via phpmyadmin it goes perfectly! Does anyone know why I am experiencing this problem? Link to comment https://forums.phpfreaks.com/topic/46453-mysql-problem/ Share on other sites More sharing options...
Wildbug Posted April 10, 2007 Share Posted April 10, 2007 Post the code. Link to comment https://forums.phpfreaks.com/topic/46453-mysql-problem/#findComment-226033 Share on other sites More sharing options...
Jumba Posted April 10, 2007 Author Share Posted April 10, 2007 This is the php code <?php // Open Connection To mySQL. // Replace 'username' and 'password' with appropiate login values for your server. $mysqlLink = mysql_connect( 'localhost' , 'username' , 'password' ); // Select mySQL Database. mysql_select_db( 'database' , $mysqlLink ); // Create Query To Create Table. $sqlfile = "punten.sql"; $handle = fopen($sqlfile, "r"); $sql_query = fread($handle, filesize($sqlfile)); fclose($handle); // Issue Query. mysql_query( $mysqlLink ) or die(mysql_error()); // Close mySQL Connection. mysql_close( $mysqlLink ); ?> This is the sql querie http://lnl.yurx.com/punten.sql (just a test sql querie Link to comment https://forums.phpfreaks.com/topic/46453-mysql-problem/#findComment-226037 Share on other sites More sharing options...
paul2463 Posted April 10, 2007 Share Posted April 10, 2007 this is where you create the query from the file $sql_query = fread($handle, filesize($sqlfile)); so why do you try and execute the connection script as the query here mysql_query( $mysqlLink ) or die(mysql_error()); try changing that to the following mysql_query( $sql_query ) or die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/46453-mysql-problem/#findComment-226045 Share on other sites More sharing options...
Jumba Posted April 10, 2007 Author Share Posted April 10, 2007 this is where you create the query from the file $sql_query = fread($handle, filesize($sqlfile)); so why do you try and execute the connection script as the query here mysql_query( $mysqlLink ) or die(mysql_error()); try changing that to the following mysql_query( $sql_query ) or die(mysql_error()); That didn't work, but i got this and it worked mysql_query($sql_query, $mysqlLink) or die(mysql_error()); But then I got another error http://lnl.yurx.com/insert.php The sql file is at http://lnl.yurx.com/punten.sql Any idea what could be wrong? Link to comment https://forums.phpfreaks.com/topic/46453-mysql-problem/#findComment-226069 Share on other sites More sharing options...
fenway Posted April 11, 2007 Share Posted April 11, 2007 And what's the error now? Link to comment https://forums.phpfreaks.com/topic/46453-mysql-problem/#findComment-226691 Share on other sites More sharing options...
paul2463 Posted April 11, 2007 Share Posted April 11, 2007 you are missing the command CREATE TABLE Table1 ("ID" INTEGER PRIMARY KEY) `ID` INT NOT NULL AUTO_INCREMENT, `Naam` VARCHAR(255) NULL, `Toets_Hsft_1` VARCHAR(255) NULL, `Toets_Hsft_2` INT NULL, `Toets_Hsft_3` INT NULL, `HSFT_4` INT NULL, PRIMARY KEY (`ID`) ) TYPE=MyISAM; Link to comment https://forums.phpfreaks.com/topic/46453-mysql-problem/#findComment-226694 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.