close ad
WARNING: Do Not Install the DREAMWEAVER CC 2017 or 2018 Update »
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Connect to 2 different databases on the same page

Thread began 1/27/2017 11:03 am by Accumike | Last modified 2/01/2017 3:59 pm by Ray Borduin | 432 views | 6 replies |

Accumike

Connect to 2 different databases on the same page

This is a bit complicated... I want to pull property information from another web site & database into my CRM system.

I can do this if I include two connections at the top of the page:

<?php require_once('../Connections/crm_realpress_wa.php'); ?>
<?php require_once('../Connections/realpress_property.php'); ?>

The first handles my crm data, the second my property data. No problem.

But I want to make the second db connection dynamic, so that the crm user can connect to different databases as required.

Using the old ADDT recordset extension, I have done this by making a db query at the top of the second connection and then passing the info into the actual connection parameters.

This is similar code for MySQLi:

<?php require_once('../Connections/crm_realpress_wa.php'); ?>
<?php require_once('../webassist/mysqli/rsobj.php'); ?>
<?php // Get Connections to Property Database in RealPress site
$rsDBConnections = new WA_MySQLi_RS("rsDBConnections",$crm_realpress_wa,0);
$rsDBConnections->setQuery("SELECT id_dbc, idlic_dbc, domain_url_dbc, connection_name_dbc, hostname_dbc, database_dbc, username_dbc, password_dbc, iddbc_lic FROM cu_db_connection_dbc LEFT JOIN cs_licensee_lic ON id_dbc=iddbc_lic WHERE idlic_dbc = ? AND iddbc_lic IS NOT NULL");
$rsDBConnections->bindParam("i", "".$_SESSION['wa_user_licence'] ."", "-1"); //colname
$rsDBConnections->execute();

# FileName="WADYN_MYSQLI_CONN.htm"
# Type="MYSQL"
# HTTP="true"
$hostname_realpress_dynamic_db = $rsDBConnections->getColumnVal("hostname_dbc");
$database_realpress_dynamic_db = $rsDBConnections->getColumnVal("database_dbc");
$username_realpress_dynamic_db = $rsDBConnections->getColumnVal("username_dbc");
$password_realpress_dynamic_db = $rsDBConnections->getColumnVal("password_dbc");
@session_start();
$realpress_dynamic_db = new mysqli($hostname_realpress_dynamic_db, $username_realpress_dynamic_db, $password_realpress_dynamic_db, $password_realpress_dynamic_db);
$realpress_dynamic_db->set_charset('utf8');
?>

I then replace the connection 'realpress_property' with 'realpress_dynamic_db' and it should connect.

Howver, I have tried this using the code above, but it won't work - all I get is the actual SQL SELECT query showing on the page and nothing else.

Am I doing something wrong, or is this no longer possible with MySQLi?

All suggestions welcome, thanks.

Sign in to reply to this post

Ray BorduinWebAssist

It seems like this would work. I'd need FTP access and a URL to debug.

Sign in to reply to this post

Accumike

Hi Ray, login / FTP details emailed to you.

Sign in to reply to this post

Ray BorduinWebAssist

I didn't get them. Please just add them to the private area of a reply on this thread.

Sign in to reply to this post

Accumike

Details sent.

Sign in to reply to this post

Ray BorduinWebAssist

Your connection file had:
$realpress_dynamic_db = new mysqli($hostname_realpress_dynamic_db, $username_realpress_dynamic_db, $password_realpress_dynamic_db, $password_realpress_dynamic_db);

instead of:
$realpress_dynamic_db = new mysqli($hostname_realpress_dynamic_db, $username_realpress_dynamic_db, $password_realpress_dynamic_db, $database_realpress_dynamic_db);

(your password variable was repeated instead of having the database name)

Sign in to reply to this post

Accumike

That's embarassing. Sorry about this, I looked at itmany times and still didn't see it!

Anyway, it works fine now.

Thanks for your help.

Sign in to reply to this post

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...