Jump to content

Database connection variable


ChrisTERiS

Recommended Posts

Hello all,

 

Can someone help me to find which variable holds the database connection to use it in mysqli queries?

Or do I need to create a new database connection using data from configuration.php file?

Have some scrirpts ready using mysqli, Smarty templates and Bootstrap, and I want to avoid big changes by using PDO.

 

eg in my Forum script I'm using:

$sql_forum = mysqli_query($db,"SELECT * FROM " . TABLE_PREFIX . "forums WHERE id=$forumid ORDER BY id ASC LIMIT 1");

 

Thank you

Edited by ChrisTERiS
Link to comment
Share on other sites

Finally I added a connection and I used my own variable.

require __DIR__ . '/init.php';
// Connect to Database
$db = mysqli_connect($db_host, $db_username, $db_password, $db_name);
if (mysqli_connect_errno())
{
   echo "Failed to connect to Database: " . mysqli_connect_error();
}

Link to comment
Share on other sites

if these are for use in hooks, I wouldn't have thought you'd need to use your db details...

 

https://developers.whmcs.com/advanced/db-interaction/

 

Thank you. No, I don't plan to use it in hooks. In simple pages like: https://www.cmsbulletin.com/whmcs/forum.php

 

PDO with transaction (and rollback) are something that I was using back to 1987 with Clipper 5 for Dos. The only that I remember now is the meaning :)

 

After 10 years that I came back to WHMCS coding, what I can say is that things became much better, but I'm missing the easy of use of vBulletin database manager. Just $db->query_read, $db->query_write etc etc and you can do anything in any place you want. Maybe vB is on EOL, but some things remain without competition.

 

Again thank you !

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