我的网站上有一张地图,您可以在这张地图上添加位置和信息。但是在保存并关闭时我得到了这个错误
Data Loaded: <br />
<b>Fatal error</b>: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [2005] Unknown MySQL server host '$host' (25)' in /home/sea503/public_html/phpsqlinfo_addrow.php:11
Stack trace:
#0 /home/sea503/public_html/phpsqlinfo_addrow.php(11): PDO->__construct('mysql:host=$hos...', '**************', '************')
#1 {main}
thrown in <b>/home/sea503/public_html/phpsqlinfo_addrow.php</b> on line <b>11</b><br />
我的代码看起来像这样
<?php
require("dbinfo.php");// database connections
// Get parameters from URL
$lat = $_GET["lat"];
$lng = $_GET["lng"];
$name = $_GET["name"];
$time = $_GET["time"];
$description = $_GET["description"];
$sighting = $_GET["sighting"];
//Connect to database
try {
$dbh = new PDO("mysql:host=$host;dbname=$database",$username,$password);
} catch (PDOException $e) {
echo 'error :' .$e->getMessage();
}
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
try {
// Prepare INSERT statement new sigting
$stmt3 = $dbh->prepare("INSERT INTO tbl_maps (ID, map_client_name, client_time, client_lat, client_lng, client_description, client_sighting) VALUES (NULL, ?, ?, ?, ?, ?, ?)");
// Assign parameters
$stmt3->bindParam(1,$name);
$stmt3->bindParam(2,$time);
$stmt3->bindParam(3,$lat);
$stmt3->bindParam(4,$lng);
$stmt3->bindParam(5,$description);
$stmt3->bindParam(6,$sighting);
$stmt3->execute();
$data[] = array("name"=>$name, "lat"=>round($lat,6), "lng"=>round($lng,6),"time"=>$time,"description"=>$description,"sighting"=>$sighting);
//Data for success
echo json_encode($data);
}
catch(PDOException $e) {
echo "Error Message.". $e->getMessage() ;// Remove or modify after testing
file_put_contents('PDOErrors.txt',date('[Y-m-d H:i:s]').", phpsqlinfo_addrow.php, ". $e->getMessage()."\r\n", FILE_APPEND);
}
//Close the connection
$dbh = null;
?>
这需要 30 秒左右,我最终得到一个错误消息。请有人可以帮我解决这个问题
然后dbinfo是
$host="41.185.13.51;port=3307"; $database="kruger_park_live"; $username="sean_sql"; $password="******";