# !/usr/local/bin/perl -w BEGIN { my $base_module_dir = (-d '/home/bcnagle/perl' ? '/home/bcnagle/perl' : ( getpwuid($>) )[7] . '/perl/'); unshift @INC, map { $base_module_dir . $_ } @INC; } use strict; use DBI; use XML::Parser::PerlSAX; my $path; my $Product_ID; my $Updated; my $Quality; my $Supplier_id; my $Prod_ID; my $Catid; my $On_Market; my $Model_Name; my $Product_View; my $HighPic; my $HighPicSize; my $HighPicWidth; my $HighPicHeight; my $Date_Added; my $dbh= connect_to_db(); my $insert= $dbh->prepare( "INSERT INTO files (path, Product_ID, Updated, Quality, Supplier_id, Prod_ID, Catid, On_Market, Model_Name, Product_View, HighPic, HighPicSize, HighPicWidth, HighPicHeight, Date_Added) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);"); $insert->bind_param( 1, $path); $insert->bind_param( 2, $Product_ID); $insert->bind_param( 3, $Updated); $insert->bind_param( 4, $Quality); $insert->bind_param( 5, $Supplier_id); $insert->bind_param( 6, $Prod_ID); $insert->bind_param( 7, $Catid); $insert->bind_param( 8, $On_Market); $insert->bind_param( 9, $Model_Name); $insert->bind_param( 10, $Product_View); $insert->bind_param( 11, $HighPic); $insert->bind_param( 12, $HighPicSize); $insert->bind_param( 13, $HighPicWidth); $insert->bind_param( 14, $HighPicHeight); $insert->bind_param( 15, $Date_Added); my $twig = new XML::Parser(); $twig->parse( "/home/bcnagle/public_html/files.index.xml" ); $dbh->disconnect(); exit; sub connect_to_db { my $driver = "mysql"; my $dsn = "DBI:$driver:database=database;"; my $dbh = DBI->connect($dsn, 'uname', 'pword', {AutoCommit=>1}); my $drh = DBI->install_driver($driver); return( $dbh); } sub start_element { my($twig, $file) = @_; if ($file->{Name} eq 'file') { $path = $file->{Attributes}->{'path'}; $Product_ID = $file->{Attributes}->{'Product_ID'}; $Updated = $file->{Attributes}->{'Updated'}; $Quality = $file->{Attributes}->{'Quality'}; $Supplier_id = $file->{Attributes}->{'Supplier_id'}; $Prod_ID = $file->{Attributes}->{'Prod_ID'}; $Catid = $file->{Attributes}->{'Catid'}; $On_Market = $file->{Attributes}->{'On_Market'}; $Model_Name = $file->{Attributes}->{'Model_Name'}; $Product_View = $file->{Attributes}->{'Product_View'}; $HighPic = $file->{Attributes}->{'HighPic'}; $HighPicSize = $file->{Attributes}->{'HighPicSize'}; $HighPicWidth = $file->{Attributes}->{'HighPicWidth'}; $HighPicHeight = $file->{Attributes}->{'HighPicHeight'}; $Date_Added = $file->{Attributes}->{'Date_Added'}; $insert->execute(); $twig->purge; exit; #debug and testing purpose, write 1 line then exit. } else { #do nothing } } sub end_element { } sub start_document { } sub end_document { exit; } #### ...repeat with new items and so on to a total of approximately a 1gb file