joshuaceo Posted December 6, 2008 Share Posted December 6, 2008 How can I import a .csv file to a mysql database? Or at least a long list. For example i would like to import this list into a mysql database: assets/images/economyhalt12401_thumbnail.jpg assets/images/economyhalt12401_thumbnail.jpg assets/images/165310-bag-in-a-bag_thumbnail.jpg assets/images/123810_thumbnail.jpg assets/images/polos1_thumbnail.gif assets/images/stlourdnsheepboots_thumbnail.jpg assets/images/double-safety.05_thumbnail.jpg assets/images/148684_thumbnail.gif assets/images/203111_thumbnail.gif assets/images/106242_thumbnail.gif assets/images/203110_thumbnail.gif assets/images/203109_thumbnail.gif assets/images/stud-plugs_thumbnail.gif assets/images/stud-plugs(1)_thumbnail.gif assets/images/ez-mount-western_thumbnail.gif assets/images/239407_thumbnail.jpg assets/images/239411_thumbnail.jpg assets/images/239415-braided-visalia_thumbnail.gif assets/images/239419d-dark-stained_thumbnail.gif assets/images/246033l-stirrup_thumbnail.jpg assets/images/239408_thumbnail.jpg assets/images/239412_thumbnail.jpg assets/images/shenshowreins_thumbnail.jpg assets/images/159012(1)_thumbnail.gif assets/images/shendouble-stitchreins(1)_thumbnail.jpg assets/images/159013_thumbnail.gif assets/images/159010_thumbnail.gif assets/images/nw50_thumbnail.gif assets/images/159014_thumbnail.gif assets/images/beta-combo-bridle_thumbnail.jpg assets/images/159016beta-rein_thumbnail.jpg assets/images/race-bridle_thumbnail.gif *it would be much longer, this is just a sample Quote Link to comment https://forums.phpfreaks.com/topic/135768-importing-a-csv-to-mysql/ Share on other sites More sharing options...
dclamp Posted December 6, 2008 Share Posted December 6, 2008 well since your post is "real urgent" i guess i can help... Do you have PHPMyAdmin, i am pretty sure they allow CSV imports. btw, we dont care if it is important. we will get to your post when we get to it. Quote Link to comment https://forums.phpfreaks.com/topic/135768-importing-a-csv-to-mysql/#findComment-707458 Share on other sites More sharing options...
joshuaceo Posted December 6, 2008 Author Share Posted December 6, 2008 i have phpmyadmin. where can i find this import feature? Quote Link to comment https://forums.phpfreaks.com/topic/135768-importing-a-csv-to-mysql/#findComment-707466 Share on other sites More sharing options...
salami1_1 Posted December 6, 2008 Share Posted December 6, 2008 i have phpmyadmin. where can i find this import feature? select your db, select the table then go to 'IMPORT / EXPORT' tab then just browse for your csv and up it. Quote Link to comment https://forums.phpfreaks.com/topic/135768-importing-a-csv-to-mysql/#findComment-707476 Share on other sites More sharing options...
ashishag67 Posted December 6, 2008 Share Posted December 6, 2008 This code will help you:- first upload the csv file at a location into csv folder $uploaddir = 'csv/'; $uploadfile = $uploaddir . basename($_FILES['file']['name']); $find=".csv"; $str=$_FILES['file']['name']; $pos=strpos($str, $find); if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadfile)) { $msg="File is valid, and was successfully uploaded."; } else { $msg="Possible file upload attack!"; } //file has been uploaded now import the file contents to the db $handle = fopen($uploadfile, "r"); while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { $num = count($data); $row++; for ($c=0; $c < $num; $c++) { echo $data[$c] . "<br />\n"; } //the csv file contains two data i.e. $data[0] contains name field and $data[1] contains email field $name=$data[0]; $emailID=$data[1]; $query=mysql_query("SELECT * FROM details where emailID='$emailID'"); $n=mysql_num_rows($query); if($n==0) { $query=mysql_query("INSERT INTO `details`(`name`, `emailID`) VALUES('$name', '$emailID')"); $ins++; } } fclose($handle); ?> cheer! enjoy check this website http://www.mysqlandphp.net Quote Link to comment https://forums.phpfreaks.com/topic/135768-importing-a-csv-to-mysql/#findComment-707486 Share on other sites More sharing options...
Mchl Posted December 6, 2008 Share Posted December 6, 2008 And there's of course LOAD DATA INFILE syntax Quote Link to comment https://forums.phpfreaks.com/topic/135768-importing-a-csv-to-mysql/#findComment-707502 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.