我是pdo和php的新手,所以请容忍我。
我想要的是创建与数据库的安全连接并获取数据。但当我检查时,连数据库连接都没有。当我检查元件时发现:
加载资源失败:服务器以500的状态响应
(内部服务器错误)
我查过了,我想我知道那是什么意思,但我修不好
这是我的密码,
global $dbname = $_GET['dbname'];
global $table = $_GET['table'];
global $yerId= $_GET['gid'];
try {
$db = new PDO("pgsql:dbname=$dbname;host=localhost", "postgres", "postgres" );
$sql = $db->query ("SELECT km, turu, hat_kesimi, ili, ilcesi, mahadi FROM $table WHERE gid = $yerId ");
while($result = $sql-> fetch(PDO_FETCH_ASSOC) ) {
printf ('<table><thead><tr><th colspan="4" align="left" >TCDD 3.BOLGE MUDURLUGU <img src="tcdd.png" align="right" width="92px" /></th></tr><tr><th colspan="4">Hemzemin Gecitler ve Ozellikeri</th></tr></thead><tbody><tr><th>Kilometre</th><td colspan="3">%s</td></tr><tr><th>Turu</th><td colspan="3">%s</td></tr><tr><th>Hat Kesimi</th><td colspan="3">%s</td></tr><tr><th>Sehir</th><td colspan="3">%s</td></tr><tr><th>Ilce</th><td colspan="3">%s</td></tr><tr><th>Mahalle</th><td colspan="3">%s</td></tr><tr><th colspan="4" > copyright © all rights reserved by Piri Reis Bilisim </th></tr></tbody></table>', $result["km"],$result["turu"], $result["hat_kesimi"], $result["ili"], $result["ilcesi"],$result["mahadi"]);
}
$dbh = null;
}
catch(PDOException $e)
{
echo $e->getMessage();
}
最佳答案
当我通过PHP -l
运行您的代码时,会收到以下错误消息:
PHP Parse error:语法错误,第2行test.PHP中意外的“=”,应为“,”或“;”
分析test.php时出错
只需删除此处的global
关键字,这是错误的:
$dbname = $_GET['dbname'];
$table = $_GET['table'];
$yerId= $_GET['gid'];