0

I'm having an issue and I don't know if it's related to the SSH tunnel but here's the deal.

I have a simple function to connect to the database from php and it works fine locally but it doesn't work to connect to a remote server.

connect.php

$dbhost = '172.1.2.3';
$dbuser = 'root';
$dbpass = 'testpass';
$db = 'testdb';

function dbconnect()
{
$conn = mysqli_connect($dbhost, $dbuser, $dbpass, $testdb);
$conn->set_charset("utf8");

error_reporting( E_ALL & ~E_DEPRECATED & ~E_NOTICE );
if(!$conn)
    {
        die('We are unable to connect you to the site! --> '.mysqli_error());
    }
else
    {   
        return $conn;
    }
}

Then, I include this file say on index.php and do the following.

<?php
include 'connect.php';
$conn = dbconnect();
?>

//html content below

the problem I'm having is that when I do the $conn = dbconnect(); the index.php page doesn't load, I just get a blank page. if I comment out $conn = dbconnect(); then the HTML content loads just fine.

I'm not getting error outputs on the console either so I'm a bit clueless as to what the problem might be and I don't know if it's related to the SSH tunneling which I don't know how to include it on the php connection function.

I do however, have to use the SSH credentials to connect to the database from any mysql manager so I want to believe I am missing something in the function.

if it helps, the server is running PHP 5.6 and mysql 5.7.22

Any help is appreciated.

Thanks,

BlueSun3k1
  • 757
  • 5
  • 21
  • 39
  • 1
    It probably took me less time to search for a duplicate than it took you to write the question – RiggsFolly Jul 20 '18 at 14:45
  • I have already gone over some of the posts on stack and I have not found anything that works which is why I am asking the question. None of the questions and answers I have found include working with a function so I do not know if it has anything to do with the way the function is structured or something else. I just noticed the linked question and I've tried that but it doesn't work for me. – BlueSun3k1 Jul 20 '18 at 14:49

0 Answers0