I need to connect to MySQL using PHP, but database is on a other host , I can't do It correctly.
I'm useing this code. Error is in this line:
$mysqli = new mysqli("hostex.lt","myInfo","pass","myInfoo");
"hostex.lt". Database is in hostex.lt, phpMyAdmin: myadmin.hostex.lt I've tried It but It always print error:error:error:error:error:error:error:error:error:error:
This code working in other project where I use localhost, so here is problem.
for($i=1;$i<=10;$i++)
{
if ($stmt = $mysqli->prepare("INSERT into game (taskai, userName) VALUE (?,?) ")) {
if (!$mysqli->set_charset("utf8")) {
printf("Error loading character set utf8: %s\n", $mysqli->error);
} else {
// printf(" ", $mysqli->character_set_name());
}
$stmt->bind_param('ss', $score, $name);
// $stmt->bind_param("s", $username);
$stmt->execute();
if ($stmt->error != '') {
echo ' error:'.$stmt->error;
} else {
echo 'success';
}
$stmt->close();
} else {
echo 'error:'.$mysqli->error;
}
}
$mysqli->close();
?>
UPDATE
I've got this error:
By default MySQL only allows access from localhost, if you want to access it from a different host you have to allow it explicitly.
Log into PHPMyAdmin, go to Privileges, add a user 'myDbName'@'www.ftpDomainName.lt' (the host part after the @ is important) and give it access to your database.
If you don't have access to the Privileges section in your PHPMyAdmin you will have to contact the hoster of your database.
This is unlikely to be a PHP problem per se , but most probably something on the database server that is blocking the connection.
Try the following in this order, running your code after each step:
New MySQL user
Database Server
On the database server ask the sysadmin to edit /etc/mysql/my.cnf (assumption is that this is a Linux machine with the my.cnf stored at this location -- your sysadmin will know how to find the correct file).
Firewall
If the above steps haven't worked, then most likely a firewall is blocking the connection.
Note that if the sysadmin of the MySQL server does not want to open the port on the firewall or enable external connections to the database, there is not a lot you can do
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.