Sunday, December 12, 2010

Basic Query to retrive,update & delete any records in Drupal 7

Retreive Record
--------------
$actions = db_query('SELECT * FROM {users}')->fetchAll();

foreach ($actions as $action) {
echo $action->uid;
}
?>
Displays uid

Update Record
---------------
Similar to Drupal6
db_query("UPDATE {node} SET title = 'Kumaresanfgh' WHERE nid =2");
?>

Delete Record
--------------
Similar to Drupal6
db_query("DELETE FROM {node} WHERE `nid` =2");
?>

Insert a Record
---------------
Similar to Drupal6
db_query("INSERT INTO {TABLE} (`source` ,`alias` ,`language`)VALUES ('sdsd', 'sdsd', 'dsdsd')");
?>

No comments:

Post a Comment