-2

I'm creating an Android App that needs to connect to a remote Db. So i'm using Json and a PHP page. For testing, i've installed EasyPhp. This is the script that i made for test.

I've added the local address in the config of apache.

  <?php
$cf = 'prova';
$cognome = 'prova';
$nome = 'prova';
$data = '1993-08-02';
$telefono = 'prova';
$email = 'prova';
$codice = 'aaaaa';
echo($cf);
$conn = mysql_connect('192.168.0.100:3306', 'root', '');
mysql_select_db('voceparkinsondb',$conn);
if (!$conn) {
    die('Could not connect: ' . mysql_error());
}
$risultato = mysql_query("INSERT INTO paziente(CF, Cognome, Nome, DataNascita, Telefono, Email, CodiceAttivazione) VALUES ('$cf', '$cognome','$nome','$data', '$telefono', '$email', '$codice')") or die('Errore: ' .mysql_error());
?>

and this is the error that i've recived

Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in C:\Program Files (x86)\EasyPHP-DevServer-14.1VC11\data\localweb\scripts\AddRecord.php on line 14

Warning: mysql_connect(): Impossibile stabilire la connessione. Rifiuto persistente del computer di destinazione. in C:\Program Files (x86)\EasyPHP-DevServer-14.1VC11\data\localweb\scripts\AddRecord.php on line 14

Warning: mysql_select_db() expects parameter 2 to be resource, boolean given in C:\Program Files (x86)\EasyPHP-DevServer-14.1VC11\data\localweb\scripts\AddRecord.php on line 15
Could not connect: Impossibile stabilire la connessione. Rifiuto persistente del computer di destinazione.

Where's the problem? Thanks

Francesco de Guytenaere
  • 4,443
  • 2
  • 25
  • 37
  • mysql funcions deprecated, refer http://stackoverflow.com/questions/15321620/deprecated-mysql-functions check @Your Common Sense answer – Anto S Jul 13 '15 at 10:54
  • Deprecated functions is not the problem here, it is in that second warning which mentions that a connection cannot be established to the database. I guess, it would be nice to get a translation of that warning/error. – Gimby Jul 13 '15 at 11:02
  • "Unable to establish connection . Persistent refusal of the target computer". It looks like the MySQL server IP (192.168.0.100) is rejecting your connection. Is it a different machine than what you are developing on (i.e. not "localhost")? Check the server's firewall to make sure connections on port 3306 are allowed. Also make sure the MySQL service is running and accepting connections on the right interfaces... – Kinnectus Jul 13 '15 at 11:31
  • Have you turned on your mysql server/service/process? – STT LCU Jul 13 '15 at 11:48
  • It's not in localhost, 192.168.0.100 is the Ip address of the machine where is on the webserver – Francesco Introna Jul 14 '15 at 11:14

1 Answers1

0

Firstly you should use SQLi as it's more updated, and is more secure. This will solve the deprecation error.

As Big Chris said, the connection is not being allowed. So either check you have the right connection, and that the user you're accessing with (root, which is a bad idea as it's unsecure) are both correct. Make sure that you are using the correct database. Does the root account not have a password too? I noticed you haven't entered once so that could be the problem (unless you really don't have a password.)

To connect, try this:

$conn = mysqli_connect("192.168.0.100:3306","root","","voceparkinsondb") or die("Error " . mysqli_error($conn)); 

That should allow you to connect to the db automatically, but just test it to be sure.

Also, if you're using something such as phpMyAdmin make sure you allow root to have access from the IP you are connecting from. As well as making sure that you have the firewall open and there is nothing using that port.

Francisco
  • 10,918
  • 6
  • 34
  • 45
owenvoke
  • 228
  • 4
  • 16