REF : https://www.codeigniter.com/userguide2/database/active_record.html
$ q = $ this ->db ->query ("select * from test_user where data_id = ? " , array ($ data_id ));
echo "<br>Last Query = " . $ this ->db ->last_query (); // View Last query
//Option 2
$ this ->db ->select ('title, content, date ' );
$ this ->db ->from ('mytable ' );
$ query = $ this ->db ->get ();
//Option 3
$ this ->db ->select ('title, content, date ' );
$ this ->db ->where ('title ' , $ title );
$ this ->db ->where ('status ' , $ status );
$ this ->db ->where ('name != ' , $ name );
$ this ->db ->where ('id < ' , $ id ); // AND SQL
$ query = $ this ->db ->get ('mytable ' );
//Option 4
$ this ->db ->select ('title, content, date ' );
$ array = array ('name ' => $ name , 'title ' => $ title , 'status ' => $ status );
$ this ->db ->where ($ array ); // AND SQL
$ query = $ this ->db ->get ('mytable ' );
$ data = array (
'title ' => $ title ,
'name ' => $ name ,
'date ' => $ date
);
$ this ->db ->where ('id ' , $ id );
$ this ->db ->update ('mytable ' , $ data );
// Option2
$ this ->db ->update ('mytable ' , $ data , "id = 4 " );
// Option 3
$ this ->db ->update ('mytable ' , $ data , array ('id ' => $ id ));
// Option 4 - With Set
$ this ->db ->set ('data2 ' , '1000 ' ); // normal ESCAPE STRING !!!
$ this ->db ->set ('data ' , 'data + 1 ' , false ); // NOT ESCAPE STRING !!!
$ this ->db ->where ('pagenum ' , $ pagenum );
$ this ->db ->update ('table1 ' );
// Display Last SQL for Verify
echo "<br>LastSQL= " ;
echo $ this ->db ->last_query ();
$ data = array (
'title ' => 'My title ' ,
'name ' => 'My Name ' ,
'date ' => 'My date '
);
$ this ->db ->insert ('mytable ' , $ data );
// Otion - Use Set for Insert
$ this ->db ->set ('name ' , $ name );
$ this ->db ->set ('title ' , $ title );
$ this ->db ->set ('status ' , $ status );
$ this ->db ->insert ('mytable ' );
$ this ->db ->where ('id ' , $ id );
$ this ->db ->delete ('mytable ' );
Display View ( My Style in Codeigniter )
$ args = [] ;
$ args ['rows ' ] = $ rows ;
$ args ['a_valxy ' ] = $ a_valxy ;
$ args ['b_found ' ] = $ b_found ;
$ args ['num_rows ' ] = $ num_rows ;
$ view_args = [ 'Menu1 ' => ["home " , 'banana/home ' ]
,'Menu2 ' => ["Link " , 'Link/list_link_home ' ]
];
$ args ['webobj ' ] = ['viewpage ' => "orange_preview "
,'args ' => $ view_args
];
/* DISPLAY VIEW include header + body + footer */
$ this ->load ->view ('my_master_frame1.php ' , ['args ' =>$ args ] );
function __construct () {
parent ::__construct ();
safeguard_check_controller_construct (); // in Helper Function
}
/* both paramter is string */
function field_exist ($ field ,$ table ){
assert (is_string ($ field ));
assert (is_string ($ table ));
$ require1 = $ field ;
$ uf = $ this ->db ->list_fields ($ table );
//$msg = "table admin must have field $require1 " ;
if ( in_array ($ require1 , $ uf )){
return true ;
}else {
return false ;
}
}