Forums | Mahara Community
Proper way to insert a record to a particular db table?
04 August 2009, 14:28
How do you insert a record into a table within the db? I'm trying to insert a record into the blocktype_wall_post table and nothing shows up in the db table once the query is ran.
04 August 2009, 18:45
Hi - the insert_record() in lib/dml.php is what you want. There's plenty of examples of using it in the source, but as a quick example:
$record = new stdClass;
$record->fieldname = 'fieldvalue';
$record->field2 = 'fieldvalue';
If you want the ID back:
$id = insert_record('tablename', $record, 'id', true);