How to use the findByField function of the fleaphp crud operation
- 2020-05-05 10:58:14
- OfStack
findByField function prototype
The findByField function parameter states
$field provides the field
for the query $value provides the value
for the query $sort sort
$fields requires a query to display the field name
Example of findByField function for fleaphp crud operation
/**
* 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);
}
The findByField function parameter states
$field provides the field
for the query $value provides the value
for the query $sort sort
$fields requires a query to display the field name
Example of findByField function for fleaphp crud operation
$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');
// Linked database
$dsn = array(
'driver' => 'mysql',
'host' => 'localhost',
'login' => 'root',
'password' => '',
'database' => 'wordpress'
);
FLEA::setAppInf('dbDSN',$dsn);
// read wp_posts The content of the
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);