How to create a new record via api

A place for users and developers of the Xataface to discuss and receive support.

How to create a new record via api

Postby si_fly » Tue Apr 20, 2010 8:52 am

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!
si_fly
 
Posts: 3
Joined: Wed Mar 31, 2010 2:58 am

Re: How to create a new record via api

Postby shannah » Tue May 04, 2010 9:05 am

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');
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm


Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 4 guests

cron
Powered by Dataface
© 2005-2007 Steve Hannah All rights reserved