Using D/Xataface API, vs standard mysql_query statements
Archived from the Xataface Users forum.
mikewassil — Fri Feb 13, 2009 5:33 pm
In a post quite a few versions ago, Mon Apr 17, 2006 9:29 pm, you explained the possiblity of using D/Xataface API, vs standard mysql_query statements on the frontend applications. I’m interested in trying that and have a test underway. Unfortunately, I’ve run into a snag straight away.
- Code: Select all
- `// initialize dataface framework
require_once ‘/path/to/dataface/dataface-public-api.php’;
df_init(FILE, ‘/url/to/dataface’);$query = array();
$profiles =& df_get_records(‘Profiles’, $query);
…
while ( $profiles->hasNext() ){
$profile =& $profiles->next();`
I get the following error:
Fatal error: Call to a member function hasNext() on a non-object..
I’ve searched a bit with no luck finding anything to explain what is missing and causing this error. Much appreciate any suggestions. Thanks.
Michael
shannah — Sat Feb 14, 2009 6:57 am
Hi Michael,
This means that $profiles is likely null (meaning that the call to df_get_records()) didn’t find anything.
An alternative, if you prefer to work with arrays (rather than iterators) is to use the df_get_records_array() function:
$profiles =& df_get_records_array(‘Profiles’, $query);
if ( !$profiles ) {echo “No Profiles found!”;exit;}
foreach ($profiles as $profile ){
…
}
.