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);
}
Copy the 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 database
$dsn = array(
'driver' => 'mysql',
'host' => 'localhost',
' login' => 'root',
'password' => '',
'database' => 'wordpress'
);
FLEA::setAppInf('dbDSN',$dsn);
//Read Get 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);
The above introduces how to use the findByField function of fleaphp fleaphp crud operation, including fleaphp content. I hope it will be helpful to friends who are interested in PHP tutorials.