PHP Classes

load to db

Recommend this page to a friend!

      SimpleXLSX  >  All threads  >  load to db  >  (Un) Subscribe thread alerts  
Subject:load to db
Summary:problem loading xlsx data to db
Messages:3
Author:Seth Watson
Date:2011-12-26 01:10:59
Update:2011-12-26 20:19:54
 

  1. load to db   Reply   Report abuse  
Picture of Seth Watson Seth Watson - 2011-12-26 01:11:00
I have tried a few different methods to pass the parsed xlsx data to my db, but they are not working. This is what I have so far. I'm new to php so any help would be greatly appreciated. I have also tried with implode, but not working either. Thanks!


// attempt a connection
$con = mysql_connect('localhost', 'root', '');
mysql_select_db('testdb2');
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
// end connection



if (isset($_FILES['file'])) {

require_once "simplexlsx.class.php";

$xlsx = new SimpleXLSX( $_FILES['file']['tmp_name'] );

list($cols,) = $xlsx->dimension();

foreach( $xlsx->rows() as $k => $r) {
if ($k == 0) continue; // skip first row
for( $i = 0; $i < $cols; $i++)
mysql_query("INSERT INTO table (prQty, prMode, prPrem, prComm) VALUES (?, ?, ?, ?)");
}
}

// close connection
mysql_close($con);

  2. Re: load to db   Reply   Report abuse  
Picture of Sergey Shuchkin Sergey Shuchkin - 2011-12-26 18:40:38 - In reply to message 1 from Seth Watson
$xlsx = new SimpleXLSX( $_FILES['file']['tmp_name'] );

foreach( $xlsx->rows() as $k => $r) {

if ( $k == 0 ) continue; // skip first row

mysql_query("INSERT INTO table SET prQty='$r[0]', prMode='$r[1]', prPrem='$r[2]', prComm='$r[3]'");

}

  3. Re: load to db   Reply   Report abuse  
Picture of Seth Watson Seth Watson - 2011-12-26 20:19:54 - In reply to message 2 from Sergey Shuchkin
Much thanks Sergey! Works perfect!