I want to upload an Excel file into a MySQL table without using PDO, but just with a simple MySQL connection.
I want to load the Excel file using DOMDocument::load
but can't get it to work.
Here's what I've tried so far:
mysql_connection("localhost", "root", "");
mysql_select_db("excel");
function add_data($abc, $pqr, $xyz) {
$str = "INSERT INTO excel(abc, pqr, xyz) VALUES('$abc', '$pqr', '$xyz')";
$qry = mysql_query($str);
}
if (isset($_FILES['file'])) {
$dom = DOMDocument::load($_FILES['file']['tmp_name']);
$rows = $dom->getElementsByTagName('Row');
$first_row = true;
foreach ($rows as $row) {
if (!$first_row) {
$abc = "";
$pqr = "";
$xyz = "";
$index = 1;
$cells = $row->getElementsByTagName('Cell');
foreach ($cells as $cell) {
$ind = $cell->getAttribute('Index');
if ($ind != null)
$index = $ind;
if ($index == 1)
$abc = $cell->nodeValue;
if ($index == 2)
$pqr = $cell->nodeValue;
if ($index == 3)
$xyz = $cell->nodeValue;
$index += 1;
}
add_data($abc, $pqr, $xyz);
}
$first_row = false;
}
}