简体   繁体   中英

Connection refused when I try to connect via php to mysql database over android app

I have a mysql database running on my local machine and I use wamp. I can login with phpmyadmin. Everything looks fine, create tables and users. When I try to connect with php I get the message connection refused. The same when I try 127.0.0.1/connect.php in my browser. If I have a wrong user in my php file I get the message that user ist wrong.

Here my connect.php

<?php
   $conn = mysqli_connect("127.0.0.1", "root", "", "users");
    if ($conn) {
        die('no connection: '. mysqli_connect_error());
    }
    echo 'connected';
        mysqli_close($conn);
?

I tried everything, localhost, IP, 10.0.2.2, but nothing works. I also checked mysql settings and I read most of the posts here.

I solved the problem.

With this code it works perfect

<?php
$conn = new mysqli("127.0.0.1", "root", "", "users");
if (mysqli_connect_errno()) {
    echo "no connection " . mysqli_connect_error();
}
echo 'conneted';
mysqli_close($conn);
?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM