示例:mydatabase位于google.com/phpmyadmin上 我想从yahoo.com/insertdata.php
插入数据两个域都不在同一台服务器上,两个域都在不同的服务器上 那么如何连接数据库
<?php
$server = "38.89.136.77";
$database = "dbname";
$username = "dbusers";
$password = "password";
$mysqlConnection = mysqli_connect($server, $username, $password);
if (!$mysqlConnection)
{
echo "Please try later.";
}
else
{
mysqli_select_db($database, $mysqlConnection);
echo " database is connected";
}
?>
此代码无法正常工作如何才能获得错误请稍后再试。
答案 0 :(得分:0)
这样做。然后你会显示所有错误。
<?php
$mysqli = new mysqli("localhost", "user", "password", "database");
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
?>
然后在评论中发布您的错误,我可以帮助您。