Jump to content

Not able to connect to external Database


Brawlz
 Share

Recommended Posts

Hi,

I hope this is the correct section for my problem.

All I need is a connection to an external Database and a query gettings some data. I do this in a processwire Page-Template. I am honestly not sure if it is a problem with processwire or my code:

$host = XXXXX’;

$user = XXXXX‘;

$pass = XXXXX‘;

$db = XXXXX‘;

$port = 3306‘;



$mydb = new Database($host, $user, $pass, $db , $port); 

$result = $mydb->query("SELECT * FROM char“); 

while($row = $result->fetch_assoc()) {

 print_r($row); 

}

 

Produces the following error:

Error: Exception: DB connect error 2002 - Connection timed out (in /customers/9/4/e/XXXX.de/httpd.www/wire/core/Database.php line 79)

 

I also tried connecting without the $port variable but got the same error.

Link to comment
Share on other sites

Are those quotes actually single quotes ' ? I'd try to remove them from the $port, as it's just an integer anyway.

For an example of how to use the PW DB handlers, see this post from @ryan: 

Or you can use plain PHP functions (PDO, mysqli...) instead.

If the error persists, you simply don't have the correct DB credentials.

Link to comment
Share on other sites

Yeah I didn't think it would make a difference for the port to be given as string or integer. I now tried using plain PHP but got the same error, guess it's the credentials then. Thanks for your suggestions!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...