Page 1 of 1

How to create a new record via api

PostPosted: Tue Apr 20, 2010 8:52 am
by si_fly
Hi,

System: win7 server, xampp for mysql, apache and php 5.3.1 + xataface version which works.

The database and xataface front end are working fine and I have been developing a basic gui environment using xataface to work with.

I am using xataface as one half of a web system and my code needs to manipulate the data in the database. I could code up my proprietay system to access the database, change records, add new ones, etc, but xataface obviously has these so I am planning to create applications which will use the api to do all the tasks.

I can find api examples and code to do everything I need apart from to add a new record and populate it with information.

I can see that the add record button on xataface uses an action to create a new record in table X.

Can I use this action to add the new data at the same time? Or can I pick up the id for the new record, find it and get my code to add the data, then update?

It seems like something everyone would need to do, but I can't find any examples on the web which work.

A working code example of how to use php to do this would be such a help!

Re: How to create a new record via api

PostPosted: Tue May 04, 2010 9:05 am
by shannah
Are you looking for PHP code to add a new record?

Code: Select all
$record = new Dataface_Record('my_table', array());
$record->setValues(array(
    'name'=>'Steve',
    'email'=>'foo@example.com'
));
$res = $record->save();   // Doesn't check permissions
//  $res = $record->save(null, true);  // checks permissions

if ( PEAR::isError($res) ){
    // An error occurred
    throw new Exception($res->getMessage());
}

// If there was an auto increment  id field, it will now be populated
$record->val('id');