Forums | Mahara Community

Developers /
Proper way to insert a record to a particular db table?


anonymous profile picture
Account deleted
Posts: 34

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. 

anonymous profile picture
Account deleted
Posts: 1643

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';
insert_record('tablename', $record); 

If you want the ID back:

$id = insert_record('tablename', $record, 'id', true); 
2 results