Jump to content

Safe to use DB info in blocks


Morpheusxeno

Recommended Posts

I am creating some module that needs information from the database, is it safe to store

$servername = "";
$username = "";
$password = "";
$dbname = "";

$conn = new mysqli($servername, $username, $password, $dbname);

$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 

$online = 0;

Into a block which is loaded on the front page?

If its not, what is the require path to use so I can store the DB info in a file that can be accessed by the block.
I am having an issue making the block require the database info without using an absolute path.

Link to comment
Share on other sites

Please don't do that... It's poor practice.

https://invisioncommunity.com/developers/docs/fundamentals/accessing-the-database-r166/

If you're connecting to your Invision DB for data, use \IPS\Db, how to use the methods are in the System/Db/Db.php file or the above doc.

\IPS\Db::i()->select()

If you're connecting to a remote DB..... 

  1. Store the data in your conf_global.php file so it's protected just like your Invision DB details. 
  2. Use \IPS\Db::i('your_remote_name',$connectionSettings)
  3. Populate $connectionSettings array from conf_global.php values you added for your remote DB.
require( \IPS\ROOT_PATH . '/conf_global.php' );

$connectionSettings['sql_host'] = $INFO['your_remote_db_...']
$connectionSettings['sql_user'] = $INFO['your_remote_db_...']
$connectionSettings['sql_pass'] = $INFO['your_remote_db_...']
$connectionSettings['sql_database'] = $INFO['your_remote_db_...']
$connectionSettings['sql_port'] = $INFO['your_remote_db_...']
$connectionSettings['sql_socket'] = $INFO['your_remote_db_...']
$connectionSettings['sql_tbl_prefix'] = $INFO['your_remote_db_...']

 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

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