LiveRecord使い方一覧?! 
月曜日, 12月 11, 2006, 02:39 AM -  PHP
LiveRecord 一つずつ説明しようと思ったけども・・・一応コチラで開発しているときのテストコードのっけときます。見た方がはやいとおもって(笑)

        //------------------------------------------------------------
// INSERT VALUES テスト
//------------------------------------------------------------

$arrParams = array();

$objTBL->id = 9;
$objTBL->name = '入力データ';
$objTBL->insert( $arrParams );

unset( $arrParams );

//------------------------------------------------------------
// INSERT VALUES テスト2
//------------------------------------------------------------

$arrParams = array();
$arrParams[ LiveRecord::SUFFIX ] = ' aaaaaaaa ';

$objTBL->id = 9;
$objTBL->name = '入力データ';
$objTBL->insert( $arrParams );

unset( $arrParams );



//------------------------------------------------------------
// INSERT SELECT テスト
//------------------------------------------------------------

$arrParams = array();
$arrParams[ 'columns' ] = array( "MAX( id ) + 1", ':name' );
$arrParams[ 'where' ] = '';

$objTBL->id = 10;
$objTBL->name = '入力データ10';
$objTBL->insert( $arrParams );

unset( $arrParams );


//------------------------------------------------------------
// INSERT SELECT テスト2
//------------------------------------------------------------

$arrParams = array();
$arrParams[ 'columns' ] = array( "MAX( id ) + 1", ':test_param' );
$arrParams[ 'where' ] = '';
$arrParams[ 'binds' ] = array( 'test_param' => 'ほげー!' );

$objTBL->id = 10;
$objTBL->name = '入力データ12';
$objTBL->insert( $arrParams );

unset( $arrParams );



//------------------------------------------------------------
// UPDATE テスト
//------------------------------------------------------------

$objTBL->id = 10;
$objTBL->name = '入力データUPDATE';
$objTBL->update();


//------------------------------------------------------------
// UPDATE テスト2
//------------------------------------------------------------

$arrParams = array();
$arrParams[ 'where' ] = 'id = 55';

$objTBL->objRows->clearParameters();
$objTBL->name = 'aaaaaaaaa';
$objTBL->update( $arrParams );

unset( $arrParams );


//------------------------------------------------------------
// UPDATE テスト3
//------------------------------------------------------------

$arrParams = array();
$arrParams[ LiveRecord::WHERE ] = 'id = 1';
$arrParams[ LiveRecord::SUFFIX ] = ' AND id = 2';

$objTBL->objRows->clearParameters();
$objTBL->name = '更新';
$objTBL->update( $arrParams );

unset( $arrParams );


//------------------------------------------------------------
// DELETE テスト1
//------------------------------------------------------------

$objTBL->delete();


//------------------------------------------------------------
// DELETE テスト2
//------------------------------------------------------------

$arrParams = array();
$arrParams[ 'where' ] = 'id = 55';

$objTBL->delete( $arrParams );

unset( $arrParams );


//------------------------------------------------------------
// DELETE テスト3
//------------------------------------------------------------

$arrParams = array();
$arrParams[ LiveRecord::WHERE ] = 'id = 1';
$arrParams[ LiveRecord::SUFFIX ] = ' AND id=9';

$objTBL->delete( $arrParams );

unset( $arrParams );


//------------------------------------------------------------
// SELECT テスト
//------------------------------------------------------------

$arrParams = array();
$arrRows = $objTBL->select( $arrParams );


//------------------------------------------------------------
// SELECT テスト2
//------------------------------------------------------------

$arrParams = array();
$arrParams[ 'where' ] = 'id=2';
$arrRows = $objTBL->select( $arrParams );



//------------------------------------------------------------
// SELECT テスト3
//------------------------------------------------------------

$arrParams = array();
$arrParams[ LiveRecord::COLUMNS ] = array( 'id' => 'popop', 'name' => 'hogehoge' );
$arrParams[ LiveRecord::BINDS ] = array( "atari" => "%ほ" );
$arrParams[ LiveRecord::WHERE ] = "name LIKE :atari";
$arrParams[ LiveRecord::ORDER_BY ] = array( 'id' => 'ASC' );
$arrRows = $objTBL->select( $arrParams );


//------------------------------------------------------------
// SELECT テスト3
//------------------------------------------------------------

$arrParams = array();
$arrParams[ LiveRecord::COLUMNS ] = array( 'id' => 'popop', 'name' => 'hogehoge' );
$arrParams[ LiveRecord::ORDER_BY ] = array( 'id' => 'DESC' );
$arrParams[ LiveRecord::LIMIT ] = 2;
$arrParams[ LiveRecord::OFFSET ] = 0;
$arrRows = $objTBL->select( $arrParams );


//------------------------------------------------------------
// SELECT テスト4
//------------------------------------------------------------

$arrParams = array();
$arrParams[ LiveRecord::COLUMNS ] = array( 'SUM( id )' => 'popop', 'name' => 'hogehoge' );
$arrParams[ LiveRecord::GROUP_BY ] = array( 'id' );
$arrRows = $objTBL->select( $arrParams );

//------------------------------------------------------------
// SELECT テスト5
//------------------------------------------------------------

$arrParams = array();
$arrParams[ LiveRecord::COLUMNS ] = array( 'SUM( id )' => 'popop', 'name' => 'hogehoge' );
$arrParams[ LiveRecord::GROUP_BY ] = array( 'id' );
$arrParams[ LiveRecord::HAVING ] = " SUM( id ) > 11 ";
$arrRows = $objTBL->select( $arrParams );


//------------------------------------------------------------
// SELECT テスト6
//------------------------------------------------------------

$arrParams = array();
$arrParams[ LiveRecord::COLUMNS ] = array( 'SUM( id )' => 'popop', 'name' => 'hogehoge' );
$arrParams[ LiveRecord::GROUP_BY ] = array( 'id' );
$arrParams[ LiveRecord::HAVING ] = " SUM( id ) > 11 ";
$arrParams[ LiveRecord::PREFIX ] = " ";
$arrParams[ LiveRecord::SUFFIX ] = " OR SUM(id) < 11; ";
$arrRows = $objTBL->select( $arrParams );


//------------------------------------------------------------
// SELECT テスト7 CROSS JOIN
//------------------------------------------------------------

$arrParams = array();
$arrParams[ LiveRecord::JOINS ][] = array(
LiveRecord::JOIN_TYPE => 'CROSS',
LiveRecord::JOIN_TABLE => 'tbl_hoge'
);
$arrParams[ LiveRecord::JOINS ][] = array(
LiveRecord::JOIN_TYPE => 'CROSS',
LiveRecord::JOIN_TABLE => 'tbl_hoge2'
);
$arrRows = $objTBL->select( $arrParams );



//------------------------------------------------------------
// SELECT テスト8 CROSS JOIN2
//------------------------------------------------------------

$objTBLHoge = new tbl_hoge( $this->objDatabase->getConnection() );
$arrTempParams[ LiveRecord::WHERE ] = 'c_id = 1';


$objTBLHoge2 = new tbl_hoge2( $this->objDatabase->getConnection() );
$arrTempParams2[ LiveRecord::WHERE ] = 'c_id = 1';


$arrParams = array();
$arrParams[ LiveRecord::JOINS ][] = array(
LiveRecord::JOIN_TYPE => 'CROSS',
LiveRecord::JOIN_TABLE => $objTBLHoge,
LiveRecord::JOIN_PARAMS => $arrTempParams
);
$arrParams[ LiveRecord::JOINS ][] = array(
LiveRecord::JOIN_TYPE => 'CROSS',
LiveRecord::JOIN_TABLE => $objTBLHoge2,
LiveRecord::JOIN_PARAMS => $arrTempParams2
);
$arrRows = $objTBL->select( $arrParams );



//------------------------------------------------------------
// SELECT テスト9 INNER JOIN
//------------------------------------------------------------

$arrParams = array();
$arrParams[ LiveRecord::JOINS ][] = array(
LiveRecord::JOIN_TYPE => 'INNER',
LiveRecord::JOIN_TABLE => 'tbl_hoge',
LiveRecord::JOIN_LFN => 'tbl_test.id',
LiveRecord::JOIN_RFN => 'tbl_hoge.c_id'
);
$arrRows = $objTBL->select( $arrParams );


//------------------------------------------------------------
// SELECT テスト9 INNER JOIN2
//------------------------------------------------------------

$objTBLHoge = new tbl_hoge( $this->objDatabase->getConnection() );
$arrTempParams[ LiveRecord::WHERE ] = 'c_id = 3';

$objTBLHoge2 = new tbl_hoge2( $this->objDatabase->getConnection() );
$arrTempParams2[ LiveRecord::WHERE ] = 'c_id = 3';

$arrParams = array();
$arrParams[ LiveRecord::JOINS ][] = array(
LiveRecord::JOIN_TYPE => 'RIGHT OUTER',
LiveRecord::JOIN_TABLE => $objTBLHoge,
LiveRecord::JOIN_PARAMS => $arrTempParams,
LiveRecord::JOIN_LFN => 'tbl_test.id',
LiveRecord::JOIN_RFN => 'tbl_hoge.c_id'
);
$arrParams[ LiveRecord::JOINS ][] = array(
LiveRecord::JOIN_TYPE => 'RIGHT OUTER',
LiveRecord::JOIN_TABLE => $objTBLHoge2,
LiveRecord::JOIN_PARAMS => $arrTempParams,
LiveRecord::JOIN_LFN => 'tbl_test.id',
LiveRecord::JOIN_RFN => 'tbl_hoge2.c_id'
);
$arrRows = $objTBL->select( $arrParams );




小堤 
火曜日, 12月 12, 2006, 08:28 AM
おお、久しぶりっ!
忘れてないよ(笑)

うちの社内に片山くんもしっている人が2名ほどいるかも(^^;
まぁちょくちょく連絡くださいw

片山 
火曜日, 12月 12, 2006, 02:49 AM
ども、2年ほど前に一緒に仕事してた片山です。

まさか忘れたとか・・・。

ある方にあなたが作ったフレームワークを教えられて、それをヒントにぐぐってみたら、このブログ見つけました。

すごいな、会社作っちゃったんやな。有言実行なかなか格好いいじゃないですか。

ちょっとだけソース見たけど、俺の職場じゃまずこんなきれいなソース見れないです・・・。日本語のコメントが書かれたきれいなソースはなかなかみれないから、時間があるときに、xFrameworkのソースをゆっくり拝見させていただきます。

ほんじゃ、がんばってください。


コメント 

コメントを書く

必要事項とコメントを入力して下さい。









タグの挿入


:) :( :o :|