简体   繁体   English

加载的数据: <br /> 致命错误 :消息未捕获的异常“ PDOException”

[英]Data Loaded: <br /> <b>Fatal error</b>: Uncaught exception 'PDOException' with message

I have searched for solutions but nothing seems to be working. 我已经在寻找解决方案,但似乎没有任何效果。 I have added the port 3307 (web africa) south africa.but I still get this error 我已经添加了端口3307(web africa)南非。但仍然出现此错误

Data Loaded: 加载的数据:
Fatal error : Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [2002] Connection timed out' in /home/sea503/public_html/phpsqlinfo_addrow.php:11 Stack trace: 0 /home/sea503/public_html/phpsqlinfo_addrow.php(11): PDO->__construct('mysql:host=mysq...', NULL, NULL) 1 {main} 致命错误 :/home/sea503/public_html/phpsqlinfo_addrow.php:11中未捕获的异常“ PDOException”,消息为“ SQLSTATE [HY000] [2002]连接超时”:0堆栈跟踪:0 /home/sea503/public_html/phpsqlinfo_addrow.php( 11):PDO-> __ construct('mysql:host = mysq ...',NULL,NULL)1 {main}
thrown in /home/sea503/public_html/phpsqlinfo_addrow.php on line 11 在第11行的/home/sea503/public_html/phpsqlinfo_addrow.php中抛出

My code looks like this 我的代码看起来像这样

<?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
$dbh = new PDO("mysql:host=mysql.spri.co.za;port=3307;dbname=kruger_park_live",$sean_sql,$########);
$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; 
?>

and the dbinfo.php like this 和这样的dbinfo.php

<?php
 $host= "****;port=3307"; $username="****"; $password="****"; $database="****"; $dbname="****";


?>

You are doing 你在做

$dbh = new PDO("mysql:host=...;dbname=...,$s..,$P..);
      // I removed the actual values for your security

but your variables are 但是你的变量是

$host= ""; 
$username="..."; 
$password="...";
$database="...";

I believe you want to do 我相信你想做

$dbh = new PDO("mysql:host=$host;dbname=$database",$username,$password);

you set your variable, but were using the values as the variable names 您设置了变量,但是使用了这些值作为变量名

this is apparent when looking at this line in the error message - 在错误消息中查看此行时,这很明显-

PDO->__construct('mysql:host=mysq...', NULL, NULL)
                                       ^^^^  ^^^^

I have made "" to single '' 我已将""设为单身''

$dbh = new PDO("mysql:host=myhost;port=xxxx;dbname=db_name",$sean_sql,$########);

to

$dbh = new PDO('mysql:host=myhost;port=xxxx;dbname=db_name','$username','$password');

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 致命错误:未捕获的异常“PDOException” - Fatal Error: Uncaught exception 'PDOException' 致命错误:未捕获的异常 &#39;PDOException&#39;,消息为 &#39;SQLSTATE[42000]: - Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: PHP致命错误:消息为&#39;SQLSTATE [42000]的未捕获异常&#39;PDOException&#39; - PHP Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000] 致命错误:未捕获异常“PDOException”,消息“找不到驱动程序” - Fatal error: Uncaught exception 'PDOException' with message 'could not find driver' PHP致命错误:消息为&#39;SQLSTATE [42000]的未捕获异常&#39;PDOException&#39;: - PHP Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: 致命错误:具有2个查询的未捕获异常&#39;PDOException&#39; - Fatal error: Uncaught exception 'PDOException' with 2 queries 致命错误:未捕获异常&#39;PDOException&#39;,消息&#39;SQLSTATE [HY000]:常规错误&#39;中 - Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000]: General error' in 致命错误:带有消息&#39;SQLSTATE [42000]的未捕获异常&#39;PDOException&#39;:语法错误或访问冲突PHP和PDO - Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation PHP & PDO 致命错误:消息为“ SQLSTATE [42000]”的未捕获异常“ PDOException”:语法错误或访问冲突:1064 - Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 致命错误:消息中出现“ SQLSTATE [HY093]:无效的参数编号:未定义参数”的未捕获异常“ PDOException” - Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter number: parameter was not defined' in
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM