How to Use the findByField function for fleaphp crud operations

Source: Internet
Author: User

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 );

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.