perl簡単なmysql操作の小さなプログラム

939 ワード

#!/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."
";