2015-10-13 84 views
0

我想連接到我的技術學院的MySQL服務器.. 我的PHP文件 db_config.php無法連接到MySQL服務器「aetos.it.teithe.gr」(111)

<?php 
/* 
All Database connection variables 
*/ 
define("DB_SERVER", "aetos.it.teithe.gr"); 
define("DB_DATABASE", "votingdb"); 
define("DB_USER", "[email protected]"); 
define("DB_PASSWORD", ".."); 

?> 

db_connect.php

<?php 

    /* 
A class file to connect to database 
*/ 
class DB_CONNECT{ 

    /* 
    function to connect with database 
    */ 
    function connect(){ 
    //import database connection variables 
    require_once __DIR__ . "/db_config.php"; 

    //connecting to mysql database 
    $con = mysqli_connect(DB_SERVER, DB_USER, DB_PASSWORD, DB_DATABASE) or die (mysqli_connect_errno() . PHP_EOL); 

//returning connection cursor 
if (!is_null($con)){ 
    return $con; 
    } 
    } 

} 

test_connection.php

<?php 

    /* 
    get firm(table) from votingdb database details(firm_name, email, ...) 
    */ 

//array for json response 
$response = array(); 

//include db_connect class 
require_once __DIR__ . "/db_connect.php"; 

//initialise DB_CONNECT class 
$db_connect = new DB_CONNECT(); 

//get $link for the db connection link 
$link = $db_connect->connect(); 

//get firm_name field from firm table 
$result = mysqli_query($link, "SELECT firm_name, city FROM Firm"); 

if (!empty($result)){ 
    echo nl2br("firm has " . mysqli_num_rows($result) . " firms\n"); 

    $response["firms"] = array(); 

    while ($row = mysqli_fetch_array($result)){ 
    //temp user array 
    $firm = array(); 
    $firm["firm name"] = $row["firm_name"]; 
    $firm["firm city"] = $row["city"]; 

    //push single product into final response array 
    array_push($response["firms"], $firm); 
    } 

    //success 
    $response["success"] = 1; 

    //echo json response 
    echo json_encode($response, JSON_PRETTY_PRINT); 

    //free result set 
    mysqli_free_result($result); 
    //close connection 
    mysqli_close($link); 
} 
else { 
    $response["success"] = 0; 
    $response["message"] = "No firms found"; 

    echo json_encode($response, JSON_PRETTY_PRINT); 
    } 


?> 

當我運行test_c onnection.php我得到以下錯誤...警告:mysqli_connect():(HY000/2003):無法連接到/ home/student/x0809中的'aetos.it.teithe.gr'(111)上的MySQL服務器/tsironis/public_html/Ptixiaki/db_connect.php 16行2003 任何人都可以解釋我做錯了什麼?

我還加my.cnf文件

[client] 
    socket=/home/student/x0809/tsironis/mysql/run/mysql.sock 

    [mysqld_safe] 
    socket=/home/student/x0809/tsironis/mysql/run/mysql.sock 

    [mysqld] 
    socket=/home/student/x0809/tsironis/mysql/run/mysql.sock 
    pid-file=/home/student/x0809/tsironis/mysql/run/mysql.pid 
    log=/dev/null 
    log-error=//home/student/x0809/tsironis/mysql/log/mysql.log 
    log_bin=/home/student/x0809/tsironis/mysql/log/mysql-bin.log 
    datadir=/home/student/x0809/tsironis/mysql/data 
    tmpdir=/home/student/x0809/tsironis/mysql/tmp 

    max_binlog_size=10M 
    skip-networking 
+0

我看這就是用戶第一件事情是錯的不是 定義(「DB_USER」,「根@ localhost」的);只有 define(「DB_USER」,「root」); –

+0

第二個是:它看起來像數據庫不能到達端口3306.是否有防火牆或my.cnf中的綁定地址是本地主機。更改爲0.0.0.0 –

+0

仍然相同..我也改變了路徑到服務器...(「DB_SERVER」,「aetos.it.teithe.gr/home/student/x0809/tsironis/mysql/run/mysql 。襪子」); – tsiro

回答

1

對不起,這不是答案,但我不能格式化, 我從這裏檢查端口。端口3306是不是開放,所以你無法到達數據庫。所以,你只能通過一個隧道得到它的ssh

$ nmap aetos.it.teithe.gr 

Starting Nmap 5.20 (http://nmap.org) at 2015-10-13 19:14 CEST 
Nmap scan report for aetos.it.teithe.gr (195.251.123.232) 
Host is up (0.083s latency). 
Not shown: 985 closed ports 
PORT  STATE SERVICE 
22/tcp open  ssh 
53/tcp open  domain 
80/tcp open  http 
110/tcp open  pop3 
135/tcp filtered msrpc 
139/tcp filtered netbios-ssn 
143/tcp open  imap 
443/tcp open  https 
445/tcp filtered microsoft-ds 
993/tcp open  imaps 
995/tcp open  pop3s 
4444/tcp filtered krb524 
5432/tcp open  postgresql 
6667/tcp open  irc 
6969/tcp open  acmsoda 
+0

我是一個非常begginer所有這...你能詳細描述我怎麼能通過隧道上ssh .. – tsiro

+0

簡短的問題:你的數據庫服務器和客戶端服務器上使用Linux –

+0

在我的客戶端服務器我使用Windows ... – tsiro

相關問題