Warning: mysqli_query() expects at least 2 parameters, 1 giv

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
michaelk46
Forum Commoner
Posts: 67
Joined: Mon Oct 12, 2009 9:50 pm

Warning: mysqli_query() expects at least 2 parameters, 1 giv

Post by michaelk46 »

I posted this here because, even though the script is written in PHP, I believe the problem is MySQL related...

I recently had a problem similar to this, but I modified the script to do something else and now i am running into another issue when I run it, I get
Warning: mysqli_query() expects at least 2 parameters, 1 given in C:\wamp\www\Test\Upload\index.php on line 52. I have verified that the file is uploaded correctly and deposited into the correct folder.

Here is the offending part of the script.

Code: Select all

 
case 'csv':
                                $destfile='C:\wamp\www\Test\Upload\Files\csv\\' . basename($_FILES['upload']['name']);
                                $ret = move_uploaded_file($_FILES['upload']['tmp_name'], $destfile);
                                switch ($ret)
                                    {
                                        case false:
                                            echo htmlspecialchars('Unable to move file', ENT_QUOTES, 'utf-8');
                                        break;
                                        default:
                                            echo htmlspecialchars('File moved successfully', ENT_QUOTES, 'utf-8');
                                        break;
                                    }
                                $sql="LOAD DATA LOCAL INFILE '" . $destfile . "'
                                     INTO TABLE page
                                     FIELDS TERMINATED BY ','
                                     LINES TERMINATED BY '\r\n'
                                     IGNORE 1 LINES
                                     (id, caption)";
                                mysqli_query($sql);
                            break;
 
and here is a look at the file I am trying to merge into the database...

Image
User avatar
tr0gd0rr
Forum Contributor
Posts: 305
Joined: Thu May 11, 2006 8:58 pm
Location: Utah, USA

Re: Warning: mysqli_query() expects at least 2 parameters, 1 giv

Post by tr0gd0rr »

mysqli_query() takes different parameters than mysql_query(). mysqli_query() requires the first parameter be the connection handle created by mysqli_connect and the second be the query string. For mysql_query(), the first parameter is the query and the second parameter is the connection handle which is optional. Check the procedural style examples on http://php.net/mysqli_query
michaelk46
Forum Commoner
Posts: 67
Joined: Mon Oct 12, 2009 9:50 pm

Re: Warning: mysqli_query() expects at least 2 parameters, 1 giv

Post by michaelk46 »

Thanks Dude...
Post Reply