[PHP-users 28914] DB_common::queryがint(1)を返すのはなぜ

鈴木孝征 takamasa @ thaliana.myhome.cx
2006年 3月 31日 (金) 12:02:30 JST


PHP-users MLの皆様へ。鈴木と申します。

PostgreSQLのデータをPEARのDBクラスを使って操作していますが、
DB_resultが返ってくるところでint(1)が返ってきます。

PostgreSQLのテーブル
dart=> \d test
   テーブル "public.test"
   カラム   |  型  | 修飾語
------------+------+--------
 name       | text |
 sample     | text |
 project_id | text |

ptest.phpの内容
<?php

require_once("DB.php");
$db = DB::connect(array('phptype' => 'pgsql', 'database' => 'mydbname'));
$db -> setFetchMode(DB_FETCHMODE_ASSOC);

$pid = 'ME00367';

$sql = "select name, sample from test where project_id = ?";
$res_id = $db -> query($sql, $pid);
while($row = $res_id -> fetchRow()){
  $res_name = $db -> query("select name from test where name = ?", $row['name']); # <-- ここの$res_nameはDB_Resultオブジェクト
  while($r = $res_name -> fetchRow()) print $r['name']."\n";
  print "<hr>\n";
  var_dump($row['sample']);
  $res_sample = $db -> query("select sample from test where sample = ?", $row['sample']);

  var_dump($res_sample);		# <-- ここでint(1)と表示される

  while($r = $res_sample -> fetchRow()) print $r['sample']."\n";
  print "<hr>\n";
}

?>
ptest.phpここまで

上記のtestテーブルをproject_idをキーに検索し、nameとsampleの項目を表示しようとしています。
一度検索して得られたsampleをキーに再度検索をかけるとDBクラスのqueryメソッドがint(1)を返し
てきます(nameをキーにした場合はDB_resultオブジェクトが返ってきています)。

PEARのマニュアル(http://pear.php.net/manual/ja/package.database.db.db-common.query.php)に
はDB_resultかDB_Errorが返るとあるのですが、なぜint(1)が返ってくるのでしょうか。

testテーブルには60のproject_idがあり、そのうち3つのproject_idの場合にのみint(1)が返ってきます。
他のproject_idを使ってテストすると正常な動作が行えました。

またDBクラスを使わないでpg_connectやpg_queryを使った場合、project_id = ME00367でも正常に動作す
ることを確認しました。一方DBクラスのprepare、executeを使用してもqueryと同じくint(1)が返ってきま
した。

以下に上記のptest.phpの実行結果を載せます。

MM2dGrowth_t01d_r1
--------------------------------------------------------------------------------
string(621) "Name = D1_growth; Treatment description = An aliquot of 5 ml of an early stationary phase MM2d cell suspension (7 days after previous subculture) was inoculated into 100 ml fresh
MSS-medium (MS-salt, 3% sucrose, 0.5mg/l NAA, 0.05mg/l kinetin). Cells were incubated under continuous darkness by rotating at 130 rpm at a temperature of 27C and samples were taken every two days for
analysis. The D1 sample was taken at day 1 after subculture into fresh medium (exp. variable; time course).; Anatomy description = cell suspension; Development stage = 1 day after subculture to fresh
media; Label = Biotin; Sample type = test"

int(1)

Fatal error:  Call to a member function on a non-object in /home/takamasa/public_html/dart_devel/ptest.php on line 26

----結果ここまで-----

queryメソッドがint(1)を返す理由、int(1)を返さないようにする方法、なぜ特定のsampleの時にint(1)が返って
くるのか、わかるかたがいらっしゃいましたら教えてください。

環境
OS: VineLinux 3.1
PHP: 4.4.2
PostgreSQL: 7.4.10

以上


PHP-users メーリングリストの案内