How to use findByField function in fleaphp crud operation_PHP tutorial

WBOY
Release: 2016-07-21 15:30:06
Original
1103 people have browsed it

findByField function prototype

Copy code The 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 provides the queried field
$value provides the queried value
$sort sorting method
$fields needs to be queried Displayed field name
Usage example of findByField function in fleaphp crud operation
Copy code The code is as follows:

$dirname = dirname(__FILE__);
define('APP_DIR', $dirname . '/APP');
define('NO_LEGACY_FLEAPHP', true);
require($dirname.'/FleaPHP/FLEA/ 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 the content of wp_posts
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);

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/323264.htmlTechArticlefindByField function prototype copy code code is as follows: /** * Returns the first record with the specified field value* * @param string $field * @param mixed $value * @param string $sort * @param...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!