Jump to content

Reconnecting to database


growe

Recommended Posts

I have an add-on that uses this code...

 

global $db_host,$db_username,$db_password,$db_name;
$whmcssql = mysql_connect($db_host,$db_username,$db_password);
mysql_select_db($db_name,$whmcssql) or die("Could not connect to the database");

 

The listed code worked up until version 5.1.2

Can someone help me figure out why it no longer works

Link to comment
Share on other sites

With an addon module the mysql connection is already established so you shouldn't need any of the code you listed above just jump right to using mysql_query(), etc and it will automatically use the database connection already established by WHMCS.

Link to comment
Share on other sites

The module itself connects to an external database so I had that code at the end to reset things back to the way it was before the module ran. Without it, after the module ran, WHMCS was trying to connect to the external database instead of the correct one. Now after the upgrade to the latest WHMCS version, the add-on does not work.

Link to comment
Share on other sites

Ah ok.

 

I just tested this myself and it looks like the variables from the configuration.php file are not available from an addon module in 5.1 so a quick fix would be to include the config file:

 

include("../configuration.php");
$whmcssql = mysql_connect($db_host,$db_username,$db_password);
mysql_select_db($db_name,$whmcssql) or die("Could not connect to the database");

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated