亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費(fèi)注冊 查看新帖 |

Chinaunix

  平臺 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 3435 | 回復(fù): 3
打印 上一主題 下一主題

為何數(shù)據(jù)插入不到數(shù)據(jù)庫? [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報(bào)告]
發(fā)表于 2014-11-02 18:59 |只看該作者 |倒序?yàn)g覽
#!/usr/bin/perl -w

use strict;  
use warnings;
use DBI;
use Encode;
use strict;
use Time::localtime;
use Data:umper;
use Time::Local;
use Spreadsheet:arseExcel;
use POSIX qw(strftime);

my $dbh = DBI->connect( 'DBI:mysql:altadb',
                        '',
                        '',
                        {RaiseError=>1,AutoCommit=>0}
                      )
          || die "Database connection not made: $DBI::errstr";

my $parser   = Spreadsheet:arseExcel->new();
my $workbook = $parser->parse('products.xls');

if ( !defined $workbook ) {
    die $parser->error(), ".\n";
}

for my $worksheet ( $workbook->worksheets() ) {

    my ( $row_min, $row_max ) = $worksheet->row_range();
    #my ( $col_min, $col_max ) = $worksheet->col_range();

        #3944
        my $count = 0;
    for my $row ( $row_min .. 18 ) {
           my $catalog = $worksheet->get_cell( $row, 0 )->unformatted();
           next unless $catalog;
                   if($catalog =~ /[^0-9a-zA-Z]/) {
                                next;
                   } else {
                                my $sth = $dbh->prepare("select t.catalog from kc_product t where t.catalog = '$catalog'";
                                $sth->execute();                           
                                if (my @ary = $sth->fetchrow_array()) {
                                        print "exitsary \n";
                                        next;
                                }
                                       
                                        #$count = $count +1;
                                        my $Cname = $worksheet->get_cell( $row, 1 )->unformatted();
                                        my $Pname = $worksheet->get_cell( $row, 2 )->unformatted();
                                        my $cas = ($worksheet->get_cell( $row, 3 )? $worksheet->get_cell( $row, 3 )->unformatted():'');
                                       
                                        my $sql = q{insert INTO kc_product (catalog, title, chemical_name, cas) VALUES (?, ?, ?, ?)};
                                        #$sth = $dbh->prepare("insert INTO kc_product (catalog, title, chemical_name, cas) VALUES (?, ?, ?, ?)";

                    print $count." ".$sql."\n" ;
                    $count = $count + 1;
                    $sth = $dbh->prepare($sql);
                    $sth->bind_param(1, $catalog);
                    $sth->bind_param(2, $Cname);
                    $sth->bind_param(3, $Pname);
                        $sth->bind_param(4,$cas);
                        $sth->execute();
                                       
                                        #my $sql = "INSERT INTO kc_product (catalog, title, chemical_name, cas) VALUES ('$catalog', '$Cname', '$Pname', '$cas')";
                                        #$dbh->do("$sql"||        die "Couldn't insert record : $DBI::errstr";
                                        print "insert $catalog,qq/$Cname/,$Pname,qq/$cas/\n";
                                       
                        }
        }               
}
$dbh->disconnect;


論壇徽章:
0
2 [報(bào)告]
發(fā)表于 2014-11-02 19:00 |只看該作者
程序沒有報(bào)任何錯(cuò)誤,但是區(qū)查看數(shù)據(jù)庫,這兩條數(shù)據(jù)沒有插入進(jìn)去,為何?

論壇徽章:
0
3 [報(bào)告]
發(fā)表于 2014-11-02 19:09 |只看該作者
都沒人Le ,perl這么沒前途了

論壇徽章:
42
19周年集字徽章-周
日期:2019-10-14 14:35:31平安夜徽章
日期:2015-12-26 00:06:30數(shù)據(jù)庫技術(shù)版塊每日發(fā)帖之星
日期:2015-12-01 06:20:002015亞冠之首爾
日期:2015-11-04 22:25:43IT運(yùn)維版塊每日發(fā)帖之星
日期:2015-08-17 06:20:00寅虎
日期:2014-06-04 16:25:27獅子座
日期:2014-05-12 11:00:00辰龍
日期:2013-12-20 17:07:19射手座
日期:2013-10-24 21:01:23CU十二周年紀(jì)念徽章
日期:2013-10-24 15:41:34IT運(yùn)維版塊每日發(fā)帖之星
日期:2016-01-27 06:20:0015-16賽季CBA聯(lián)賽之新疆
日期:2016-06-07 14:10:01
4 [報(bào)告]
發(fā)表于 2014-11-02 19:46 |只看該作者
你忘了commit了。
前面設(shè)的autocomit=0
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報(bào)專區(qū)
中國互聯(lián)網(wǎng)協(xié)會(huì)會(huì)員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP