perl一个简单mysql操作的小程序

#!/usr/bin/perl

use Mysql;

print "Content-type: text/html /n/n";

# MySQL 配置变量
$host = "localhost";
$database = "testdb";
$tablename = "testtable";
$user = "username";
$pw = "password";

# PERL MYSQL CONNECT()
$connect = Mysql->connect($host, $database, $user, $pw);

# SELECT DB
$connect->selectdb($database);

# 定义MySQL查询
$myquery = "INSERT INTO
$tablename (id, product, quantity)
VALUES (DEFAULT,'pineapples','15')";

# 执行查询
$execute = $connect->query($myquery);

# 影响行
$affectedrows = $execute->affectedrows($myquery);

# 最后一个Insert的ID
$lastid = $execute->insertid($myquery);

print $affectedrows."
";
print $lastid."
";

你可能感兴趣的:(perl一个简单mysql操作的小程序)