Tutorials

Figaro => Databases.html

A Screenshot of Figaro

Working with Databases In Figaro

All of your php code (and Figaro shorthand) will be placed inside your Root level pages. Make sure you have configured your database settings on lines 43-46 in config.Settings.php.

There are two very useful ways to connect and pull information from your database without having to write a line of SQL. The two most useful are get(); and getBY();

Using get();

The get(); function returns all or some of the fields from the table within your database as an array. All arguments are optional and if there are no arguements then it fetches the entire table.

$Database->table_name->get($fields = array(), $conditions = null, $orderBy = null, $limit = null)

Practical Uses:

Using getBY();

The getBY(); function returns all or some of the fields from the table within your database as an array conditionally based on the table name used. I.E. getBYfieldname('1'); would return all of the fields in the database where fieldname = 1. Figaro automatically knows what all of your fieldnames are so you automatically have access to a getBY function for each table name in your database. Proper use: $Mysql->tablename->getBYfieldname('condition');

Looping Thru Arrays

The foreach loop is the basis for most of your workload in Figaro.

//define your page template
$Page = new Page('path to template');
//define your content element
$Page->defineElement($thisPage, 'path to content element');

//use get to pull info from the db
$var = $Mysql->tablename->get('field1');

//loop thru the array using the names of the fields ($data['fieldname'])
foreach ($var as $row=>$data)
{
	//use the .= to add each loops output to your variable otherwise only one result
	$varList .= $data['field1'];
}

//send varList to your  pointer in your content element
$Page->$thisPage->addContent('RIGHTCOLUMN', $varList);
//render the page
$Page->render();