Genesis perl往数据库mysql写数据
发布时间:2017-01-07 09:39:00 点击:
#!/bin/perl -w
use strict;
use Tk;
use DBI;
my $dbname = "project_status";
my $location = "localhost";
my $port = "3306"; #这是mysql的缺省
my $database = "DBI:mysql:$dbname:$location:$port";
my $db_user = "root"; #数据库的账号
my $db_pass = ""; #密码
my $dbh = DBI->connect($database,$db_user,$db_pass);
my $sql = "update project_status_user set site = 'chris' where id = 1"; #更新mysql的数据
my $sth = $dbh->prepare($sql);#结果保存在$sth中
$sth->execute() or die "无法执行SQL语句:$dbh->errstr";
$sth->finish;
$dbh->disconnect; #断开数据库连接
use strict;
use Tk;
use DBI;
my $dbname = "project_status";
my $location = "localhost";
my $port = "3306"; #这是mysql的缺省
my $database = "DBI:mysql:$dbname:$location:$port";
my $db_user = "root"; #数据库的账号
my $db_pass = ""; #密码
my $dbh = DBI->connect($database,$db_user,$db_pass);
my $sql = "update project_status_user set site = 'chris' where id = 1"; #更新mysql的数据
my $sth = $dbh->prepare($sql);#结果保存在$sth中
$sth->execute() or die "无法执行SQL语句:$dbh->errstr";
$sth->finish;
$dbh->disconnect; #断开数据库连接