By nimrod98 on
Hi everyone,
I learning how to write modules so I created a jQuery one for voting. It creates a block and it references the node id and the current user logged in to avoid multiple voting by the same individual. The problem is, it calls on an outside php script to do so. The code snippet is as follows:
$.post("/drupal6/sites/all/modules/jquery_vote/rate.php",
{ rating: $(this).html(), token: '$node->nid', user: '$user->uid'},
function(xml) {
// format result
var result = [
"Thanks for rating, current average: ",
$("average", xml).text(),
", number of votes: ",
$("count", xml).text()
];
// output result
$("#rating").html(result.join(''));
$("#rating").attr("disabled");
});
It passes on information (node nid and user uid) to the php and it gets it. However, how do I connect to the Drupal database? The information I know is in the sites/default/settings.php and the variable is usually $db_url.
So how do I pass on the information from the settings.php to a module to a separate php file?? In this case it is rate.php?
Any help greatly appreciated!
Comments
So it sounds like you need
So it sounds like you need the outside php script (rate.php) to be able to have more information from the drupal database.
Here's a good forum post with a similar question and a good description of how to connect to a drupal db from an external script. http://drupal.org/node/166409
Hope this helps.
Thank you very much! That
Thank you very much! That answered my question!
That is a good method. If it
That is a good method.
If it gives you any trouble in Drupal 6, try setting $cookie_domain='example.com'; in settings.php.
If for some reason you still want to connect to the database directly, check how the db_connect($db_url) function in includes/database.mysql.inc or in includes/database.mysqli.inc connects.