Click here to Skip to main content
13,042,630 members (84,854 online)
Rate this:
Please Sign up or sign in to vote.
I am configuring a Windows Server 2003 machine to run php. The system is currently running IIS 6 and is hosting several active websites. I am able to get php to run but when I attempt to connect to a database I receive the error "Failed to connect to MySQL: A socket operation was attempted to an unreachable host. "

This happens with any attempt to create a socket connection. The code I am using works on another server, so I know there are no errors in my code.

$debug = true;
function dbPDOConnect($dsn, $dbName){
    global $db, $debug;
		$db_usernameAdmin = *********;
		$db_passwordAdmin = **********;
    if (!$db) $db = new PDO($dsn . $dbName, $db_usernameAdmin, $db_passwordAdmin); 
  if (!$db) {
    return 0;
  } else {
    return $db;
function connectPDO($dsn,$dbName){
		global $debug;		
		$query      = NULL;
try { 
  	  $db=dbPDOConnect($dsn, $dbName);
  	  if($debug) print '<p>You are connected to the database!</p>';
		} catch (PDOException $e) {
   		 $error_message = $e->getMessage();
    if($debug) print "<p>An error occurred while connecting to the database: $error_message </p>";

I cannot find any information on this problem. Has anyone encountered this problem before? Are there any changes I can make that will allow outgoing connections?
Posted 15-Apr-13 17:29pm

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 15 Apr 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100