Querying MySQL DB within a Drupal Module

The following snippet of code will help execute DB Queries using the Drupal DB Modular capabilities:

$query = db_select('my_table', 't');
$query->fields('t', array('order_id', 'order_number', 'data'));
$query->condition('t.order_number', "$order->order_number", '=');
//$query->where("t.order_number = '".$order->order_number."'");  -- !!! This works too !!!
$result = $query->execute();
foreach($result as $record)
{
  writelog("$record->order_id : $record->order_number : $record->data\n", $const_log_filename);
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s