<?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>Sun, 03 May 2026 17:04:52 +0900</lastBuildDate>
  <pubDate>Sun, 03 May 2026 17:04:52 +0900</pubDate>
  <docs>http://blogs.law.harvard.edu/tech/rss</docs>
  <generator>59Tracker 3.2</generator>
  <item>
    <title>[gcc]iconvで文字エンコードを変換するサンプルプログラム</title>
    <description>&lt;p&gt;単にテキストファイル等の文字エンコードを変換するのであれば、iconvコマンドを使用して変換すれば良いのですが、プログラム内部で取得した文字列の文字エンコードを変換したい場合もあります。&lt;/p&gt;&lt;p&gt;以下のプログラムはLinuxやCygwinの環境でC言語のプログラムからiconvを呼び出して文字エンコードを変換する場合の手順を示したサンプルプログラムです。&lt;/p&gt;&lt;p&gt;--- tst_iconv.c ---&lt;/p&gt;&lt;pre&gt;#include &amp;lt;stdio.h&amp;gt;#include &amp;lt;iconv.h&amp;gt;#define  BUFSIZE  1024char outbuf[BUFSIZE];int convert(char const *src,            char const *dest,            char const *text,            char *buf,            size_t bufsize);main(void){    int ret;    ret = convert(&quot;SHIFT-JIS&quot;, &quot;UTF-8&quot;,                  &quot;日本語テストメッセージおはよう&quot;,                  outbuf, sizeof(outbuf));    if (ret) {        printf(&quot;%s\n&quot;, outbuf);    }    else {        printf(&quot;Oops!\n&quot;);    }}int convert(char const *src,            char const *dest,            char const *text,            char *buf,            size_t bufsize){    iconv_t cd;    size_t srclen, destlen;    size_t ret;    cd = iconv_open(dest, src);    if (cd == (iconv_t)-1) {        perror(&quot;iconv open&quot;);        return 0;    }    srclen = strlen(text);    destlen = bufsize - 1;    memset(buf, '\0', bufsize);    ret = iconv(cd, &amp;text, &amp;srclen, &amp;buf, &amp;destlen);    if (ret == -1) {        perror(&quot;iconv&quot;);        return 0;    }    iconv_close(cd);    return 1;}&lt;/pre&gt;&lt;p&gt;コンパイル方法&lt;br /&gt;$ gcc -o tst_iconv tst_iconv.c -liconv&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;http://www.linux.or.jp/JM/html/LDP_man-pages/man3/iconv.3.html&quot; target=&quot;_blank&quot;&gt;ICONV&lt;/a&gt;&lt;/p&gt;&lt;br /&gt;&lt;a href=&quot;https://59log.com/?func=detail&amp;amp;id=1982#link&quot; target=&quot;_blank&quot;&gt;Link(2)&lt;/a&gt; | &lt;a href=&quot;https://59log.com/?func=detail&amp;amp;id=1982#trackback&quot; target=&quot;_blank&quot;&gt;Trackback(0)&lt;/a&gt; | &lt;a href=&quot;https://59log.com/?func=detail&amp;amp;id=1982#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=C%E8%A8%80%E8%AA%9E&quot; title=&quot;C言語&quot;&gt;C言語&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%9F%E3%83%B3%E3%82%B0&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=1982</link>
    <pubDate>Mon, 26 Jul 2010 09:54:29 +0900</pubDate>
  </item>
  <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>
