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
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
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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.