[development] new dev q: are mysql queries possible within drupal?

Jamie Holly hovercrafter at earthlink.net
Wed Nov 18 23:33:34 UTC 2009


db_set_active('customerdb');
// Make your custom queries
db_set_active(); // Returns back to the Drupal database


Jamie Holly
http://www.intoxination.net 
http://www.hollyit.net



spartaguy spartaguy wrote:
>
> Thanks to everyone that replied.
>
>
> To summarise then:
>
>  1)  I need to make a custom module.
>  2) The module should have a block for displaying the query and a menu 
> hook
>  3) I can add the module to either primary links or navigation as a 
> menu item
>  4) Rendered HTML using mysql commands is quite straight forward
>  5) The tables being queried are easier to access within the main 
> drupal d/b but i can use a different db
>  
>
> Regarding a different db, does this command:
>
> db_set_active('customerdb');
>
> make *all* db queries go through customerdb or just the ones for my 
> module?
> ie will drupal have any issues accessing the data it needs from say 
> "drupaldb" if I dont change
> the active db back again?
>
>
>
>
>
> On Tue, Nov 17, 2009 at 9:27 AM, Earl Dunovant <prometheus6 at gmail.com 
> <mailto:prometheus6 at gmail.com>> wrote:
>
>     On Mon, Nov 16, 2009 at 7:55 AM, spartaguy spartaguy
>     <spartaguy300 at gmail.com <mailto:spartaguy300 at gmail.com>> wrote:
>
>
>          I have two databases - one is for drupal data. The other db
>         is for customer data. Inside the customer data db is a table -
>         customer_data.
>
>         I want to do a select * on customer_data in the customer
>         database and show the result on screen.
>
>         Can someone tell me how to do this?
>
>
>     Your bare bones menu item is something like this:
>
>     |  $items['mypath/%object'] = array(
>         'title' => 'Page title',
>         'description' => 'Your description goes here.',
>         'access arguments' => array('permission string'),
>         'page callback' => 'customer_display',
>       );|
>
>     Then write a function named customer_display() that runs queries
>     the way Frederik showed you and returns a string containing
>     rendered HTML.
>
>


More information about the development mailing list