External Database


Author Message
Cisco

Posted: 5/25/2009
Quote message 

Is it posible to connect to another (non-wordpress) database from within pages?

I have a directory and user login system that i would like to incorporate in to various pages within a Wordpress theme.

How do I do this?

Thanks
 
Dave Porter

Posted: 5/25/2009
Quote message 

Hi Cisco,

This is not really a Artisteer question, so is best directed to the Wordpress support forums - but I believe that yes this can be done...

You are best using the Wordpress wpdb class, then your code will use the same logic as Wordpress itself uses...
http://codex.wordpress.org/wpdb

HTH - Dave Porter
 
Garry

Posted: 5/26/2009
Quote message 

Simply include an external database with include command:

include('database_connection.php')

database_connection.php:

<?php
function runSQL($rsql) {
$rootpasswd='yourPasswordHere';
$user='yourUserHere';
$db='yourDBhere';
$dbcnx = @mysql_connect('localhost',$user,$rootpasswd,true);
if (!$dbcnx) {
echo '<p>Unable to connect to the database server at this time.</p>';
exit();
}
mysql_select_db($db, $dbcnx);
$result = mysql_query($rsql) or die ('test');
return $result;
mysql_close($connect);
}
?>
 
Dan E.

Posted: 5/26/2009
Quote message 

Garry he will need a plugin that can run PHP in a Wordpress post or page. I use include-it:

http://wordpress.org/extend/plugins/include-it/


 
Cisco

Posted: 6/3/2009
Quote message 

Thanks guys for the input. I'll ty it out when I return to the office next week and let you know how it works.