[support] Best way to post content from PHP
Michael Prasuhn
mike at mikeyp.net
Thu Aug 14 20:36:15 UTC 2008
This isn't very hard at all in Drupal. To start with querying multiple
DBs, update your settings.php to look something like this:
$db_url['default'] = the default settings for your drupal db
$db_url['mydb'] = connection settings for my db (NOTE: the two
databases must be of the same type, i.e. MySQL)
then in a custom module, do something like this:
<?php
function mymodule_save_my_data($params) {
$default_db = db_set_active('mydb');
$query = 'FETCH MY DATA - A SINGLE RECORD';
$result = db_query($query, $params)
db_set_active($default_db);
$my_data = db_fetch_object($result);
$node = array();
$node = array();
$node['title'] = $my_data->title;
$node['type'] = 'NODE TYPE GOES HERE';
$node['name'] = $my_data->author;
$node['status'] = 1;
$node['promote'] = 0;
$node['sticky'] = 0;
$log = 'Imported on: ' . date('g:i:s a');
$node['log'] = $log;
$node['CCK FIELD NAME GOES HERE'] = array(
0 => array(
'FIELD ATTRIBUTE' => $my_data->field_id,
'FIELD ATTRIBUTE' => $my_data->field_value,
'FIELD ATTRIBUTE' => '',
),
);
if ($node['title']) {
$node = (object)$node;
$node = node_submit($node);
node_save($node);
$nid = $node->nid;
$message = 'Saved as node id '. l('#'. $nid, 'node/'. $nid);
drupal_set_message($message);
}
// Optionally return the node here to whatever function called us, so
they can act on the node as well
return $node;
}
?>
And you'll have a new node with the data from your other DB, as you've
mapped it in your function.
-Mike
On Aug 14, 2008, at 1:18 PM, Errol Sayre wrote:
> I'm looking to setup a script to automatically create a monthly report
> page in drupal from my custom database. I was hoping to use the
> BlogAPI module to post my data from my application to drupal, but have
> had little luck in finding a PHP script that can do this for me that
> still works (most are outdated trying to redeclare XML-RPC functions
> built-in to php).
>
> Anyone have any experience doing this and could shed some light on the
> subject? Am I just going to have to write my own XML-RPC calls or is
> there a pre-built library that can do this via one of the supported
> APIs (blogger/mt/etc)?
>
> TIA
> --
> [ Drupal support list | http://lists.drupal.org/ ]
__________________
Michael Prasuhn
mike at mikeyp.net
http://mikeyp.net
503.488.5433
714.356.0168 cell
949.200.7670 fax
More information about the support
mailing list