I have a file csv or xml.
it has three fields
country name, birth rate, year,
I want to upload it in mysql database.
can any body provide me link of php code.
thanks.
uploading in mysql
Moderator: General Moderators
-
litebearer
- Forum Contributor
- Posts: 194
- Joined: Sat Mar 27, 2004 5:54 am
Re: uploading in mysql
example...
Code: Select all
<?PHP
$new_file = “your folder /feed.csv”;
$fcontents = file ($new_file);
foreach($fcontents as $line) {
$arr = explode( ‘,’, $line);
}
foreach($arr as $data) {
$query = “insert into `your db table` VALUES(’$data’)”;
mysql_query($query);
}
?>
Re: uploading in mysql
Check out the MySQL command LOAD DATA INFILE LOCAL ... http://dev.mysql.com/doc/refman/5.1/en/load-data.html.
-
x_mutatis_mutandis_x
- Forum Contributor
- Posts: 160
- Joined: Tue Apr 17, 2012 12:57 pm
Re: uploading in mysql
Lets you do it only from the database server's local filesystem.califdon wrote:Check out the MySQL command LOAD DATA INFILE LOCAL ... http://dev.mysql.com/doc/refman/5.1/en/load-data.html.
Use fgetcsv. It lets you specify any delimiter for your csv file, since a csv file is not always delimited by ','.
http://php.net/manual/en/function.fgetcsv.php
For xml, you can use "simplexml_load_file"
http://us.php.net/manual/en/function.si ... d-file.php
Re: uploading in mysql
Good observation, thanks for pointing that out. I agree with your advice.x_mutatis_mutandis_x wrote:Lets you do it only from the database server's local filesystem.califdon wrote:Check out the MySQL command LOAD DATA INFILE LOCAL ... http://dev.mysql.com/doc/refman/5.1/en/load-data.html.
Use fgetcsv. It lets you specify any delimiter for your csv file, since a csv file is not always delimited by ','.
http://php.net/manual/en/function.fgetcsv.php
For xml, you can use "simplexml_load_file"
http://us.php.net/manual/en/function.si ... d-file.php