<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
 <channel>
  <title>語句ログ - ニュース、プログラミング、システムトレードの用語解説</title>
  <link>https://59log.com/</link>
  <description>日本の注目ニュース、コンピュータープログラミング（C/C++,Perl,PHP,SQL）、システムトレード（FX,CFD,株価指数,先物）に関する語句（Word）を日本語や英語で解説</description>
  <lastBuildDate>Tue, 09 Jun 2026 22:03:04 +0900</lastBuildDate>
  <pubDate>Tue, 09 Jun 2026 22:03:04 +0900</pubDate>
  <docs>http://blogs.law.harvard.edu/tech/rss</docs>
  <generator>59Tracker 3.2</generator>
  <item>
    <title>[Perl]DBI経由でMySQLに接続して、SELECT文でデータを取得するサンプルプログラム</title>
    <description>&lt;p&gt;PerlのプログラムからDBI経由でMySQLに接続し、SELECT文でデータを取得する処理のサンプルプログラムです。&lt;/p&gt;&lt;p&gt;あらかじめphpMyAdminを使用してMySQLにテータベース「testdb」を作成し、以下のSQLを実行しテーブル「users」を作成、3件のレコードを登録しておきます。&lt;/p&gt;&lt;pre&gt;CREATE TABLE `users` (  `userid` varchar(100) COLLATE utf8_bin NOT NULL,  `password` varchar(250) COLLATE utf8_bin NOT NULL,  `status` int(11) NOT NULL,  `auth` int(11) NOT NULL,  `username` varchar(250) COLLATE utf8_bin NOT NULL,  `address` varchar(250) COLLATE utf8_bin NOT NULL,  `mailaddr` varchar(100) COLLATE utf8_bin NOT NULL,  `hpurl` varchar(250) COLLATE utf8_bin NOT NULL,  `widgets` text COLLATE utf8_bin NOT NULL,  `createdate` datetime NOT NULL,  `lastupdate` datetime NOT NULL,  PRIMARY KEY (`userid`)) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin;insert into `users` (`userid`,`password`,`status`,`auth`, `username`,`address`,`mailaddr`,`hpurl`,`widgets`, `createdate`,`lastupdate`)  values('admin','1234','1','0','webmaster','',  webmaster100@59log.com','http://59log.com/','',now(),now());insert into `users` (`userid`,`password`,`status`,`auth`, `username`,`address`,`mailaddr`,`hpurl`,`widgets`, `createdate`,`lastupdate`)  values('test1','5678','1','1','user 1','',  'test1@59log.com','http://59log.com/','',now(),now());insert into `users` (`userid`,`password`,`status`,`auth`, `username`,`address`,`mailaddr`,`hpurl`,`widgets`, `createdate`,`lastupdate`)  values('test2','abcd','1','1','user 2','',  'test2@59log.com','http://59log.com/','',now(),now());&lt;/pre&gt;&lt;p&gt;以下のPerlプログラムでは、テーブル「users」からステータスが1のレコードを全て取得、一旦配列に格納してから標準出力に出力しています。&lt;/p&gt;&lt;p&gt;検索条件の設定にはプレースホルダを使用し、DB処理でエラーが発生した場合は、例外処理に飛んでエラーの内容が出力されるように、RaiseErrorに1を設定しています。&lt;/p&gt;&lt;p&gt;--- mysql_select.pl ---&lt;/p&gt;&lt;pre&gt;#!/usr/bin/perluse strict;use warnings;use DBI;my $data_source = &quot;DBI:mysql:testdb&quot;; # 接続先はtestdbmy $username = &quot;test&quot;; # データベースへのアクセス権限を持つユーザーを指定my $password = &quot;abcd&quot;; # そのパスワードmy $status = 1;my @recs = ();eval {    my $dbh = DBI-&gt;connect($data_source, $username, $password,                          {RaiseError =&gt; 1, PrintError =&gt; 0});    my $sql  = &quot;select * from users where status = ?&quot;;    my $sth = $dbh-&gt;prepare($sql);    $sth-&gt;execute($status);    while (my @rec = $sth-&gt;fetchrow_array) {        push @recs, [@rec];    }    $sth-&gt;finish;    $dbh-&gt;disconnect;};if ($@) {    print &quot;Error : $@\n&quot;;}foreach my $rec (@recs) {    print join(&quot;,&quot;, @{$rec}), &quot;\n&quot;;}&lt;/pre&gt;&lt;br /&gt;&lt;a href=&quot;https://59log.com/?func=detail&amp;amp;id=1981#link&quot; target=&quot;_blank&quot;&gt;Link(6)&lt;/a&gt; | &lt;a href=&quot;https://59log.com/?func=detail&amp;amp;id=1981#trackback&quot; target=&quot;_blank&quot;&gt;Trackback(0)&lt;/a&gt; | &lt;a href=&quot;https://59log.com/?func=detail&amp;amp;id=1981#comment&quot; target=&quot;_blank&quot;&gt;Comment(0)&lt;/a&gt;&lt;br /&gt;&lt;p&gt;&lt;h3&gt;キーワード&lt;/h3&gt;&lt;p&gt;&lt;em&gt;&lt;a href=&quot;https://59log.com/?q=Perl&quot; title=&quot;Perl&quot;&gt;Perl&lt;/a&gt;&lt;/em&gt;&amp;nbsp;&lt;em&gt;&lt;a href=&quot;https://59log.com/?q=DBI&quot; title=&quot;DBI&quot;&gt;DBI&lt;/a&gt;&lt;/em&gt;&amp;nbsp;&lt;em&gt;&lt;a href=&quot;https://59log.com/?q=MySQL&quot; title=&quot;MySQL&quot;&gt;MySQL&lt;/a&gt;&lt;/em&gt;&amp;nbsp;&lt;em&gt;&lt;a href=&quot;https://59log.com/?q=%E3%82%B5%E3%83%B3%E3%83%97%E3%83%AB&quot; title=&quot;サンプル&quot;&gt;サンプル&lt;/a&gt;&lt;/em&gt;&amp;nbsp;&lt;em&gt;&lt;a href=&quot;https://59log.com/?q=%E3%83%97%E3%83%AD%E3%82%B0%E3%83%A9%E3%83%A0&quot; title=&quot;プログラム&quot;&gt;プログラム&lt;/a&gt;&lt;/em&gt;&amp;nbsp;&lt;/p&gt;&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://59log.com/&quot;&gt;語句ログ - ニュース、プログラミング、システムトレードの用語解説 - 日本の注目ニュース、コンピュータープログラミング（C/C++,Perl,PHP,SQL）、システムトレード（FX,CFD,株価指数,先物）に関する語句（Word）を日本語や英語で解説&lt;/a&gt;&lt;/p&gt;</description>
    <link>https://59log.com/?func=detail&amp;id=1981</link>
    <pubDate>Mon, 26 Jul 2010 00:12:18 +0900</pubDate>
  </item>

 </channel>
</rss>
