Jump to content

MySQL Problem


Jumba

Recommended Posts

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

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

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.