FindByField function prototype
Copy codeThe Code is as follows :/**
* Returns the first record with the specified field value.
*
* @ Param string $ field
* @ Param mixed $ value
* @ Param string $ sort
* @ Param mixed $ fields
*
* @ Return array
*/
Function & findByField ($ field, $ value, $ sort = null, $ fields = '*')
{
Return $ this-> find (array ($ field => $ value), $ sort, $ fields );
}
FindByField function parameter description
$ Field: Query Fields
$ Value indicates the queried value.
$ Sort sorting method
$ Fields: query the field names displayed.
Use findByField function for fleaphp crud operationsCopy codeThe Code is as follows: $ dirname = dirname (_ FILE __);
Define ('app _ dir', $ dirname. '/app ');
Define ('no _ LEGACY_FLEAPHP ', true );
Require ($ dirname. '/FleaPHP/FLEA. php ');
// Set the cache directory
FLEA: setAppInf ('internalcachedir', $ dirname. '/_ cache ');
// Link to the database
$ Dsn = array (
'Driver '=> 'mysql ',
'Host' => 'localhost ',
'Login' => 'root ',
'Password' => '',
'Database' => 'wordpress'
);
FLEA: setAppInf ('dbdsn ', $ dsn );
// Read wp_posts content
FLEA: loadClass ('flea _ Db_TableDataGateway ');
Class Teble_Class extends FLEA_Db_TableDataGateway {
Var $ tableName = 'wp _ posts ';
Var $ primaryKey = 'id ';
}
$ Tableposts = & new Teble_Class ();
$ Rowsets = $ tableposts-> findByField ('id', 4, 'Post _ date desc', array ('id', 'Post _ title '));
Dump ($ rowsets );