我转换了以下工作代码:
<?php
include('config.php');
$link = mysql_connect($db_host, $username, $password);
mysql_select_db($db_name);
$id= $_POST["uniqi"];
$comments= $_POST["comments"];
$comments= mysql_real_escape_string($comments);
$comments = strip_tags($comments);
$update = "UPDATE mastertable SET comments = '$comments' WHERE id_pk= '$id'";
mysql_query($update, $link);
mysql_close();
header('Location: ccccc.com/pabrowser/… Updated');
?>
到 PDO:
<?php
$id= $_POST["uniqi"];
$comments= $_POST["comments"];
$conn = new PDO("mysql:host=$db_host;dbname=$db_name", $username, $password);
$sql = "UPDATE mastertable SET comments=? WHERE id_pk=?";
$q = $conn->prepare($sql);
$q->execute(array($comments, $id));
header('Location: ccccc.com/pabrowser/… Updated');
?>
这给了我
致命错误:未捕获的异常 'PDOException' 带有消息'SQLSTATE[HY000] [2002] 无法通过 /home/content/ 中的套接字'/var/lib/mysql/mysql.sock' (2)' 连接到本地 MySQL 服务器58/9508458/html/pabrowser/comsumcompro.php:4 堆栈跟踪:#0 /home/content/58/9508458/html/pabrowser/comsumcompro.php(4): PDO->__construct('mysql:host=;dbn ...', NULL, NULL) #1 {main} 在第 4 行的 /home/content/58/9508458/html/pabrowser/comsumcompro.php 中抛出