[user name] | |
[password] | |
[DB name] | sa |
DBIの導入
$ cpan
CPAN> install DBI
DBに値を挿入する.
[insert value] | '','13','sa012','10.2.3.112' |
connectDB.pl
#!/usr/bin/perl use DBI; $user = '[user name]'; $passwd = '[password]'; $db = DBI->connect('DBI:mysql:[DB name]:localhost', $user, $passwd); $sth = $db->prepare("INSERT INTO server_list VALUES ([insert value])"); $sth->execute; $sth->finish; $db->disconnect;
DBに格納されている値を取り出し,全て表示する.
connectDB2.pl
#!/usr/bin/perl use DBI; $user = '[user name]'; $passwd = '[password]'; $db = DBI->connect('DBI:mysql:[DB name]:localhost', $user, $passwd); $sth = $db->prepare("[検索条件]"); $sth->execute; $num_rows = $sth->rows; print "該当 $num_rows 件\n"; for ($i=0; $i<$num_rows; $i++) { @a = $sth->fetchrow_array; print "[値の表示]"; } $sth->finish; $db->disconnect;
[検索条件]
SELECT * FROM server_list
[値の表示]
id=$a[0], num=$a[1] host_name =$a[2] ip_address =$a[3] \n
0 件のコメント:
コメントを投稿