944,148 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 589
  • PHP RSS
Oct 19th, 2009
0

Importing into MYSQL Database

Expand Post »
I need to import TEST.TXT (located in the same directory as my script

It has 1 Record: "6","Lunch","234"

Iget this error message: Warning: mysqli_close() expects exactly 1 parameter, 0 given in C:\wamp\www\test\import.php on line 19

Why?

Heres my script:

php Syntax (Toggle Plain Text)
  1. <?php
  2. // Connect to the MySQL server and select the corporate database
  3. $mysqli = new mysqli("localhost","user,"password,"test");
  4. // Open and parse the test.txt file
  5. $fh = fopen("test.txt", "r");
  6. while ($line = fgetcsv($fh, 1000, ","))
  7. {
  8. $id = $line[0];
  9. $item = $line[1];
  10. $price = $line[2];
  11.  
  12. // Insert the data into the sales table
  13. $query = "INSERT INTO example SET id='$id',
  14. item='$item', price='$price'";
  15.  
  16. $result = $mysqli->query($query);
  17. }
  18. fclose($fh);
  19. mysqli_close();
  20. ?>
Last edited by peter_budo; Oct 22nd, 2009 at 2:18 pm. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks)
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
niche1 is offline Offline
64 posts
since May 2009
Oct 19th, 2009
0
Re: Importing into MYSQL Database
Click to Expand / Collapse  Quote originally posted by niche1 ...
I need to import TEST.TXT (located in the same directory as my script

It has 1 Record: "6","Lunch","234"

Iget this error message: Warning: mysqli_close() expects exactly 1 parameter, 0 given in C:\wamp\www\test\import.php on line 19

Why?

Heres my script:
php Syntax (Toggle Plain Text)
  1. <?php
  2. // Connect to the MySQL server and select the corporate database
  3. $mysqli = new mysqli("localhost","user,"password,"test");
  4. // Open and parse the test.txt file
  5. $fh = fopen("test.txt", "r");
  6. while ($line = fgetcsv($fh, 1000, ","))
  7. {
  8. $id = $line[0];
  9. $item = $line[1];
  10. $price = $line[2];
  11.  
  12. // Insert the data into the sales table
  13. $query = "INSERT INTO example SET id='$id',
  14. item='$item', price='$price'";
  15.  
  16. $result = $mysqli->query($query);
  17. }
  18. fclose($fh);
  19. mysqli_close();
  20. ?>
php Syntax (Toggle Plain Text)
  1. $mysqli->close();
Sponsor
Reputation Points: 520
Solved Threads: 268
Code Monkey
ShawnCplus is offline Offline
1,564 posts
since Apr 2005
Oct 19th, 2009
0
Re: Importing into MYSQL Database
Wow!

Thank You very much!
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
niche1 is offline Offline
64 posts
since May 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Executing jar file on server php
Next Thread in PHP Forum Timeline: Password change md5 in mysql problem





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC