Jump to content

connect to db


durangod

Recommended Posts

Hi,

 

I am trying to connect to the db in a function im working on. For the Mysqli library you must have the db connection live to use the function so i need to do something like

 

$db = new ??????

 

the ? is what i dont know, whats the WHMCS class name for a new db connection. Im looking at the api now but not seeing it.

 

what im doing is working on the old bridge code to phpbb that i found on here, i am converting it to Mysqli library

 

as you can see i have added the connection var as required by the new library example mysqli_query($db,$sqlcmd)

 

but inside the function i must assign $db to a new connection and i dont know what that class is on the whmcs side.

 


/* ##########################  WHMCS SIDE ############################ */

function getusername($userid) {

$db = new ????

global $user_fieldid;
$sqlcmd = "select value from tblcustomfieldsvalues where fieldid=$user_fieldid and relid=$userid";
$result = mysqli_query($db,$sqlcmd) or die("mysqli Error in getting Username :".mysqli_error($db));
while ($row = mysqli_fetch_object($result)) {
	return $row->value;
}

}

function getuserpass($userid) {

$db = new ????

global $pass_fieldid;
$sqlcmd = "select value from tblcustomfieldsvalues where fieldid=$pass_fieldid and relid=$userid";
$result = mysqli_query($db,$sqlcmd) or die("mysqli Error in getting Username :".mysqli_error($db));
while ($row = mysqli_fetch_object($result)) {
	return $row->value;
}

}

add_hook("ClientAdd",1,"create_forum_account");

?>


Edited by durangod
Link to comment
Share on other sites

i am going to try it this way instead and see if it works.

 


function getusername($userid) {

global $user_fieldid;

$table = "tblcustomfieldsvalues";
$fields = "fieldid,relid,value";
$where =  array("fieldid"=>$user_fieldid),
          array("relid"=>$userid);
$result = select_query($table,$fields,$where);

   while ($row = mysqli_fetch_object($result)) 
{
	return $row->value;
}

}//close function	  




function getuserpass($userid) 
{

   global $pass_fieldid;

$table = "tblcustomfieldsvalues";
$fields = "fieldid,relid,value";
$where =  array("fieldid"=>$pass_fieldid),
               array("relid"=>$userid);
$result = select_query($table,$fields,$where);

   while ($row = mysqli_fetch_object($result)) 
{
	return $row->value;
}

}//close function


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