Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

extract data from excel into mysql

Status
Not open for further replies.

lenelene

Programmer
Joined
Dec 10, 2002
Messages
57
Location
MY
is there any php coding that can extract data from excel file and stored data into mysql?

anybody can share the coding?
 
If you're running PHP on Win32, you should be able to use PHP's Unified ODBC functions to access the data. It would be a matter of using ODBC functions to get the data out of Excel and MySQL functions to insert the data into MySQL.

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
i have found this coding that can display the data from csv but the problem is it didnt insert the data into mysql?why is this happen?

<?php


## Connect to a local database server (or die) ##
$dbH = mysql_connect('localhost', '', '') or die('Could not connect to MySQL server.<br>' . mysql_error());

## Select the database to insert to ##
mysql_select_db('apple_sql') or die('Could not select database.<br>' . mysql_error());



$file_name= $_FILES['csvfile']['name'];

$columnheadings = 0; ##columnheadings,whether there is field name in csv file##
$pass = 0;
$fail = 0;

$row = 1;
$handle = fopen ("$file_name","r");
while ($data = fgetcsv ($handle, 1000, ",")) {
$num = count ($data);
echo "<p> $num fields in line $row: <br>\n";
$row++;
for ($c=$columnheadings; $c < $num; $c++) {
echo $data[$c];
$insertrecord = "Insert Into `details` Values ($data[$c])";
mysql_query($insertrecord);
if(mysql_error()) {
$fail += 1; # increments if there was an error importing the record
}
else
{
$pass += 1; # increments if the record was successfully imported
}
}
}

echo "fail" .$fail."</br>";
echo "pass" . $pass;

fclose ($handle);
?>
 
Tell us what happens. What does the script print out? Any error messages?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top