Php PDO连接问题

时间:2013-12-13 00:44:41

标签: php mysql pdo

我使用以下php代码连接到远程数据库:

    <?php
    error_reporting(E_ALL);
    ini_set( 'display_errors','1');

      $db_host = "host"; 
      $db_user = "user"; 
      $db_pass = "pass"; 
      $db_name = "name"; 

      try{
        $dbc = new PDO("mysql:dbname=$db_name;host=$db_host",$db_user,$db_pass);
      }

       catch(PDOException $e){
          echo '<p>There was a problem with your connection: '.$e->getMessage().'</p>';

      }

      $query = "some query";
      $results = $dbc->query($query);

      $row = $results->rowCount();




?>

但它一直生成以下错误消息:

Warning: PDO::__construct(): php_network_getaddresses: getaddrinfo failed: Name or service not known in /example.php on line 11

There was a problem with your connection: SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known

//shouldn't this error below not even show because the try never completes?

Notice: Undefined variable: dbc in /example.php on line 25

Fatal error: Call to a member function query() on a non-object in /example.php on line 25

0 个答案:

没有答案