Sp0tteh Posted January 24, 2010 Share Posted January 24, 2010 Hey all, I'm having some problems with a module I'm trying to create. In short what I'm trying to do is add the new user into a freeradius database on another server using mysql. Now this works, the problem is that the account stays as "Pending" (In WHMCS) even though i can see the data in the freeradius database and no sql errors. function radius_CreateAccount($params) { $dbhost = 'fake'; $dbuser = 'fake'; $dbpass = 'fake'; $dbname = 'fake'; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); //mysql_select_db($dbname, $conn); //mysql_query("INSERT INTO radcheck (username, attribute, op, value) VALUES ('".$clientsdetails['email']."', 'User-Password', ':=', '".$password."')", $conn); //mysql_query("INSERT INTO radusergroup (username, groupname, priority) VALUES ('".$clientsdetails['email']."', 'Dynamic', '1')", $conn); mysql_close($conn); return "success"; } In the code above i have tried to force it with the " return "success";" but it doesn't seem to make any difference. If i comment out the "mysql_connect" line above, then it shows as "active". From my understanding PHP should have no issues creating a second sql connection. If someone could help me out or at least explain whats going on it would be greatly appreciated 0 Quote Link to comment Share on other sites More sharing options...
rmccny Posted January 24, 2010 Share Posted January 24, 2010 The problem is the way WHMCS is coded internally to use MySQL is rather sloppy as there is obviously no internal use of connection identifiers. See, how PHP works is that if you use any of the mysql_* functions if you do not pass a connection resource identifier PHP will by default use the last connection opened. Your module is working fine as you state, however your use of the other connection resource is most likely preventing WHMCS from saving the status in MySQL. So here is what's happening... 1. WHMCS opens a MySQL connection. 2. WHMCS does some stuff.. 3. Your module is called, it opens a new MySQL connection to a different server (possibly) and different table. 4. Module executes and finishes successfully. 5. Since WHMCS doesn't use connection identifiers the currently active database is still your connection. It doesn't matter if you close it or not, because if you do, then PHP has no default connection anymore. There are many ways to solve this; if you're accessing the same MySQL server as WHMCS (assuming you're running under the same MySQL user too) is to just select the WHMCS database: mysql_select_db($GLOBALS['db_name']); If you're using different credentials, or using different physical servers, then just open a new connection to the WHMCS database: mysql_connect($GLOBALS['db_host'], $GLOBALS['db_username'], $GLOBALS['db_password']); mysql_select_db($GLOBALS['db_name']); I haven't tested that code, but it should work since the WHMCS database credentials are in the global scope. 0 Quote Link to comment Share on other sites More sharing options...
Sp0tteh Posted January 24, 2010 Author Share Posted January 24, 2010 Thanks a lot for the detailed response, I'm connecting to a different server so i used the second bit of code you pasted to re-connect to the whmcs database and it worked first shot. Thanks again for the help. 0 Quote Link to comment Share on other sites More sharing options...
rmccny Posted January 26, 2010 Share Posted January 26, 2010 You're welcome, I am glad that I could assist. 0 Quote Link to comment Share on other sites More sharing options...
NorCal Internet Posted June 9, 2010 Share Posted June 9, 2010 This was helpful to me also rmccny! I was having a different, but similar issue. It seemed like when I did a query, WHMCS "Lost" it's connection to MySQL, but I couldn't figure out why... Did a quick search, and found this thread! Thanks for posting this info! 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.