user2977799
user2977799

Reputation: 140

mysql_error(): supplied argument is not a valid MySQL-Link resource

Im using this script to load csv file to mysql :

$sql = mysql_query("LOAD DATA LOCAL INFILE '".$target_file."' 
                                INTO TABLE tbl_avaibility FIELDS TERMINATED BY ',' 
                                OPTIONALLY ENCLOSED BY '\"'
                                LINES TERMINATED BY '\n'
                                IGNORE 1 LINES
                                (name, total_downtime, mttr, mtbf, uptimepercentage, grup, periode, trim, cek, key1, grouptype, groupname, iphost, ha, tier, manage, sec, min, hour, downtime, cekpercentage, test, status, ipvm, namevm, statevm, hostvm, cluster, vcenter, cekcok) SET nik_user='$user_id'");

if(!$sql)
{
    mysql_error($sql);
}

In my newest mysql its working.

In my server which is old version of mysql, mysql 5.0 its give me an error when i upload a file.

mysql_error(): supplied argument is not a valid MySQL-Link resource

Can somebody tell me what to do.

Upvotes: 0

Views: 69

Answers (1)

Scuzzy
Scuzzy

Reputation: 12332

Don't feed mysql_error() your mysql_query() result ($sql), either leave it null, or feed it the resource link from mysql_connect().

http://php.net/manual/en/function.mysql-error.php

string mysql_error ([ resource $link_identifier = NULL ] )

In this example, $link_identifier is optional, change your code to this...

if(!$sql)
{
    echo mysql_error();
}

Upvotes: 4

Related Questions