Trying Baby Steps With Database API
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:
'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:
$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";
db_set_active('mock_banner');
$insert = db_insert('tbraccd')
->fields(array(
'tran_number' => '123456',
'term_code' => '201302',
'user' => $user->uid,
))
->execute();
return $insert;
db_set_active('default');
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
Did you make sure the DB name, connection name, etc. all are matching for uppercase/lowercase?