Both PHP and Lasso can access FileMaker databases, but how do their differing approaches compare when it comes to looking at the code? This article shows that Lasso code is shorter and more easy to read for the same outcome as PHP.
Lasso provided FileMaker connectivity since its inception. In fact CDML has its roots in the early versions of the Lasso language. Both platforms have moved forwards from those days - Lasso now has datasource connectivity to a myriad of database platforms, and FileMaker provides connectivity through PHP, XML, ODBC and JDBC.
Lasso can connect to FileMaker products that support ODBC or XML publishing. These products include FileMaker Server and FileMaker Sever Advanced.
The Lasso FileMaker datasource connects via the FileMaker XML publishing engine and provides functionality included in that specification.
The Lasso ODBC datasource connector can also be used to connect to FileMaker via FileMaker Inc's ODBC driver.
Lasso has been shown to outperform PHP in responsiveness on large database connections.
One of the fundamental differences between Lasso and PHP is Lasso's concept of "datasource connectivity abstraction".
Simply put, this abstraction means that you define your datasource connectivity once within the Lasso Administration web application. Once set you do not need to continually include database access classes or config files in your connections that may risk exposing your usernames and passwords.
The following examples take for granted that the user has already set up the FileMaker datasource in the Lasso Administration web application - if you wish to view how to do this in detail please refer to the Lasso Reference section on setting up FileMaker Datasources or ODBC Datasources.
For the purposes of these examples we have a FileMaker database hosted on FMSA 11 called "Contacts", with a table/layout named "list".
[
// Variables
local( database = 'Contacts' )
local( table = 'list' )
inline(
-database=#database,
-table=#table,
'firstname'='John',
'status'='Active',
-orderBy='firstname',
-search
) => {^
'<p>Found: ' + found_count + ' records.</p>'
'<table>'
records => {^
'<tr>
<td>'
field('firstname')+' '+field('lastname')
'</td><td>'
field('company')
'</td><td>'
field('city')
'</td><td>'
field('phone')
'</td>
</tr>'
^} // records end
'</table>'
^} // inline end
]
We are going to use the same scenario as Lasso - the database is "Contacts", table is "list". However PHP does not have database abstraction and we have to manually load the DB connectivity classes.
<?php
// required classes for FileMaker connectivity and handlers
require_once 'fmview.php';
require_once 'FileMaker.php';
require_once 'error.php';
// Variables
$databaseName = 'Contacts';
$layoutName = 'list';
// Database authentication credentials
$userName = 'myUserName';
$passWord = 'mySuperSecretPassword';
$cgi = new CGI();
$cgi->storeFile();
$fm = & new FileMaker();
$fm->setProperty('database', $databaseName);
$fm->setProperty('username', $userName);
$fm->setProperty('password', $passWord);
ExitOnError($fm);
$layout = $fm->getLayout($layoutName);
ExitOnError($layout);
$compoundFind = NULL;
$record = NULL;
// Create the Compound Find command object
$compoundFind =& $fm->newCompoundFindCommand($layoutName);
// Create all find requests
$findreq1 =& $fm->newFindRequest($layoutName);
$findreq2 =& $fm->newFindRequest($layoutName);
// Specify search criterion for each find request
$findreq1->addFindCriterion('firstname', 'John');
$findreq2->addFindCriterion('status', 'Active');
// Add find requests to compound find command
$compoundFind->add(1,$findreq1);
$compoundFind->add(2,$findreq2);
// Set sort order
$compoundFind->addSortRule('firstname', 1, FILEMAKER_SORT_ASCEND);
// set skip and max values
$compoundFind->setRange(0, 50);
// Execute compound find command
$result = $compoundFind->execute();
// Get records from found set
$records = $result->getRecords();
?>
<table>
<?php
$recnum = 1;
foreach ($records as $fmrecord) {
$record = new RecordHighlighter($fmrecord, $cgi);
?>
<tr>
<td>
<?php echo nl2br($record->getField('firstname', 0) )?>
<?php echo nl2br($record->getField('lastname', 0) )?>
</td>
<td>
<?php echo nl2br($record->getField('company', 0) )?>
</td>
<td>
<?php echo nl2br($record->getField('city', 0) )?>
</td>
<td>
<?php echo nl2br($record->getField('phone', 0) )?>
</td>
</tr>
<?php $recnum++; } ?>
</table>
Both Lasso and PHP languages can access FileMaker effectively to complete the task. However, while both languages access the same FileMaker database and achieve the same output, PHP requires significantly more code (approximately 4 times as much) as compared to Lasso and is clearly a more complex process.
A greater volume of code means there is a greater chance of an inadvertant syntax error which in turn may be harder to toubleshoot - especially for the novice developer. With simpler code also comes greater productivity - more time can be spent on the web application polish and delivery than the mechanics of syntax. In addition, Lasso has previously been shown to have speed advantages over PHP. Lasso gets more done in a shorter period of time.
Lasso's database abstraction also delivers a greater degree of security - your datasource usernames and passwords are not exposed in files that are potentially accessible. In addition, Lasso has other commendable security benefits which make it easier to secure your data.
We conclude that in addition to Lasso being faster than PHP, it is also more inherently secure and significantly easier for the novice developer to learn.
Security. Speed. Simplicity. And - for the love of coding.
Author: Jonathan Guthrie
Created: 30 Jul 2011
Last Modified: 10 Aug 2011
See how Lasso performs compared to PHP for accessing FileMaker data
Please note that periodically LassoSoft will go through the notes and may incorporate information from them into the documentation. Any submission here gives LassoSoft a non-exclusive license and will be made available in various formats to the Lasso community.
©LassoSoft Inc 2015 | Web Development by Treefrog Inc | Privacy | Legal terms and Shipping | Contact LassoSoft