Trying Baby Steps With Database API

1 reply [Last post]
Last seen: 7 years 48 weeks ago
Joined: 2013-03-27

Morning All --

After watching Chris's videos on the Database API, I started working on a module where I want to do some DB interactions with an external database. The external database, for the moment, is a 2nd database residing in my MYSQL installation on my local machine.

My settings.php has the following:

$databases = array (
'default' =>
array (
'default' =>
array (
'database' => 'wcpd',
'username' => 'root',
'password' => '',
'host' => 'localhost',
'port' => '',
'driver' => 'mysql',
'prefix' => '',
'mock_banner' => array (
'default' => array (
'database' => 'mock_banner',
'username' => 'root',
'password' => '',
'host' => 'localhost',
'port' => '',
'driver' => 'mysql',
'prefix' => '',

And my module has the following:

function db_test_menu() {
$items['dbtest-page'] = array(
'page callback' => 'db_test_page',
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
return $items;

function db_test_page() {
return "Trying to insert into TBRACCD";


$insert = db_insert('tbraccd')
'tran_number' => '123456',
'term_code' => '201302',
'user' => $user->uid,

return $insert;


When I visit http://localhost/dbtest-page in my browser, the page is displayed and I see my "Trying to insert" text. However, when I look in PHPmyadmin, I see that nothing has been inserted into my external database table. The fieldnames in my table all have tbraccd_ as a prefix. I originally had those defined in my three field names. I removed them and tried it as I pasted above, with the same result.

Could someone tell me if they see something wrong with what I've done? What can I do to trouble shoot further to see if the query is executing successfully or not?

Any help would be appreciated.

Thank you!

-- Chris

Last seen: 6 years 11 weeks ago
Joined: 2016-01-19
Case sensitive?

Did you make sure the DB name, connection name, etc. all are matching for uppercase/lowercase?

Add to playlist

Add to , or

Add to new playlist:

Add to playlist
This is a member-only feature
But, it's easy to become a member

Add to cart:

Contact us

Below are the supported keyboard shortcuts for our video player.

Start / stop video
Go to next video
Go to previous video
Increase or decrease player speed by 20%
Skip ahead or go back by 15 seconds
Jump to a percentage (2 is 20%, for example)
Toggle full screen
Videos Pricing More Search
BuildAModule Logo Icon BuildAModule Logo Icon
Become a member!
1 month
6 months
10% off
12 months
20% off
All memberships come with the following:
24 / 7 access to the entire 1800+ video library
An innovative video player with a rolling transcript
Extensive Drupal and cross-platform training
A thorough and thoughtful training style
Progress tracking
Take notes on specific video sections
Intuitive multi-user management
How many users?
Go solo with a single user, or give multiple team members access through one account and get discounts by bundling multiple users into a single membership.