* Tim Johnson tim@akwebsoft.com [130102 10:15]:
When this code is executed, I get an error: as follows
<....>
PDOException: SQLSTATE[HY000] [2002] No such file or directory in db_merge() (line 2416 of /Users/http/sites/daily/includes/database/database.inc).
So what am I doing wrong?
I believe that I have solved the process of switching databases and inserting data:
I am on mac osx 10.7, and there is a socket issue for drupal 7 on macs - see : http://drupal.org/node/752856 title : """ Document OS X PDO socket installation issues """ Two steps are needed: 1) Define connection information as an entry in settings.php to the $databases array as follows:
'dba' => array ( 'default' => array ( 'driver' => 'mysql', 'database' => 'aisbooks', 'host' => 'localhost', 'username' => 'tim', 'password' => 'marion', // explicitly define the socket file for mysql 'unix_socket' => '/opt/local/var/run/mysql5/mysqld.sock', ), ),
The default setting in php.ini for pdo_mysql.default_socket is /tmp/mysql.sock - which works for non-drupal PHP, but I had to create a soft link for the 'unix_socket' value above, as is explained in the document above.
2) The following code : // Implementation of hook_form_submit in module : // form_example.module function form_example_form_submit($form,&$form_state) { $result = Database::getConnection('default','dba'); db_set_active('dba'); $fe_id = db_insert('providers') ->fields(array( 'status' => $form_state["values"]["mynumber"], 'name' => $form_state["values"]["mytextfield"], ))->execute(); db_set_active(); drupal_set_message('Your form entry has been added.'); } I hope this add something to the drupal knowledgebase. Kudos to Ernie to pointing out the 'red herring'. cheers