2010-08-17 1 views
5

Quindi un mio amico e io stiamo usando entrambi xampp su ubuntu, se questo aiuta, per collegarci tra loro, entrambi abbiamo creato lo stesso file php per connetterci, quindi usiamo de IP dell'altro, ma poi si dice un erroreAccesing XAMPP Database MySql da un altro computer

Warning: mysql_connect() [function.mysql-connect]: Host 'coke-laptop.local' is not allowed to connect to this MySQL server in /opt/lampp/htdocs/connection.php on line 2 
Could not connect: Host 'coke-laptop.local' is not allowed to connect to this MySQL server 

abbiamo questo codice nel file connection.php:

<?php 
$link = mysql_connect('10.100.161.37','root',''); 
if (!$link) { 
    die('Could not connect: ' . mysql_error()); 
} 
//echo 'Connected successfully'; 

$db_selected = mysql_select_db('Prueba', $link); 
if (!$db_selected) { 
    die ('Can\'t use Prueba : ' . mysql_error()); 
} 

// This could be supplied by a user, for example 
$firstname = 'fred'; 
$lastname = 'fox'; 

// Formulate Query 
// This is the best way to perform an SQL query 
// For more examples, see mysql_real_escape_string() 
$query = sprintf("SELECT * FROM Agencia"); 

// Perform Query 
$result = mysql_query($query); 

// Check result 
// This shows the actual query sent to MySQL, and the error. Useful for debugging. 
if (!$result) { 
    $message = 'Invalid query: ' . mysql_error() . "\n"; 
    $message .= 'Whole query: ' . $query; 
    die($message); 
} 

// Use result 
// Attempting to print $result won't allow access to information in the resource 
// One of the mysql result functions must be used 
// See also mysql_result(), mysql_fetch_array(), mysql_fetch_row(), etc. 
while ($row = mysql_fetch_assoc($result)) { 
    echo $row['ID'] . " "; 
    echo $row['Nombre'] . "\n\r"; 
} 

// Free the resources associated with the result set 
// This is done automatically at the end of the script 
mysql_free_result($result); 
mysql_close($link); 
?> 

Se usiamo il IP proprio così, siamo in grado di immettere ogni altri xampp normale pagina di benvenuto

+0

avete dato 'accesso coke laptop.local' al database? Cioè c'è un utente per quell'host che può accedere al database? – Stephen

risposta

9

Verificare di aver abilitato l'accesso remoto al server MySQL. Aprire il file my.cnf (probabilmente trovato all'interno xampp/etc /), andare alla sezione [mysqld] e aggiungere il seguente (utilizzando il proprio indirizzo IP anziché l'esempio)

bind-address=192.168.1.100 

Se c'è una riga che dice skip-networking, commento che fuori in modo che assomiglia a questo:

# skip-networking 

quindi riavviare il server MySQL

1

Sembra che il tuo database MySQL non ti permetta di connetterti in remoto con le credenziali che hai fornito. Sarà necessario configurare un utente remoto per la connessione. Prova ad esaminare MySQL Grants.

Per esempio:

GRANT SELECT, INSERT ON database.* TO 'someuser'@'somehost';