Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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.

<?php
$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>";
		}

}
connectPDO('mysql:host=webdb.uvm.edu;dbname=','LTOPPER_CS148_Final');

?>


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

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900