我的网站上有一张地图,允许用户添加标记和信息。点击并保存大约需要30到40秒,我收到此消息:
Data Loaded: error :SQLSTATE[HY000] [2003] Can't connect to MySQL server on '41.185.13.51' (110)<br />
<b>Fatal error</b>: Call to a member function prepare() on a non-object in <b>/home/sea503/public_html/phpsqlinfo_addrow.php</b> on line <b>19</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;port=$port;dbname=$database",$username,$password);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);}
catch (PDOException $e) {
echo 'error :' .$e->getMessage();
}
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;
?>
DBINFO:
<?php
$host= '41.185.13.51'; $port= '3307'; $database="kruger_park_live"; $username="sean_sql"; $password="**********";
?>
和HTML
"//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
var marker;
var infowindow;
function initialize() {
var latlng = new google.maps.LatLng(-24.532226,31.290586);
var options = {
zoom: 8,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(document.getElementById("map-canvas"), options);
var html = "<table>" +
"<tr><td>Posted by:</td> <td><input type='text' id='name'/> </td> </tr>" +
"<tr><td>Time +/-:</td> <td><input type='text' id='time'/></td> </tr>" +
"<tr><td>Sighting:</td> <td><select id='sighting'>" +
"<option value='Lion' SELECTED>Lion</option>" +
"<option value='Rhino'>Rhino</option>" +
"<option value='Elephant'>Elephant</option>" +
"<option value='Buffalo'>Buffalo</option>" +
"<option value='Leopard'>Leopard</option>" +
"<option value='Cheetah'>Cheetah</option>" +
"<option value='Spotted Hyena'>Spotted Hyena</option>" +
"<option value='Wild Dogs'>Wild Dogs</option>" +
"<option value='Hippo'>Hippo</option>" +
"<option value='Kudu'>Kudu</option>" +
"<option value='Zebra'>Zebra</option>" +
"<option value='Fish Eagle'>Fish Eagle</option>" +
"<option value='Other'>Other</option>" +
"</select> </td></tr>" +
"<tr><td>Description:</td> <td><input type='text' id='description'/> </td> </tr>" +
"<tr><td></td><td><input type='button' value='Save & Close' onclick='saveData()'/></td></tr>";
infowindow = new google.maps.InfoWindow({
content: html
});
google.maps.event.addListener(map, "click", function(event) {
marker = new google.maps.Marker({
position: event.latLng,
map: map
});
google.maps.event.addListener(marker, "click", function() {
infowindow.open(map, marker);
});
});
}
function saveData() {
var latlng = marker.getPosition();
var name = escape(document.getElementById("name").value);
var time = escape(document.getElementById("time").value);
var sighting = escape(document.getElementById("sighting").value);
var description = escape(document.getElementById("description").value);
$.get('phpsqlinfo_addrow.php',{lat:latlng.lat(),lng:latlng.lng(),name:name,time:time,sighting:sighting,description:description})
.done(function(data){
alert("Data Loaded: " + data);
});
}
{
var request = window.ActiveXObject ?
new ActiveXObject('Microsoft.XMLHTTP') :
new XMLHttpRequest;
request.onreadystatechange = function() {
if (request.readyState == 4) {
request.onreadystatechange = doNothing;
callback(request.responseText, request.status);
}
};
request.open('GET', url, true);
request.send(null);
}
</script>
我真的很感激这方面的任何帮助