The following code is saved as wel.php file
<?php header("content-type:text/html;charset=utf-8"); //设置编码 require 'pdoconfig.php'; //读取公共参数 $dsn = "{$dbType}:host={$host};dbname={$dbName}"; //创建数据源 try{ $pdo = new PDO($dsn,$userName,$password); $updateTime = time(); $sql = "update grade set name=:name,price=:price,update_time=:update_time where id=10"; $stmt=$pdo ->prepare($sql); $num = $stmt->execute([':name'=>'php',':price'=>2750,':update_time'=>$updateTime]); echo '1'; if ($num > 0){ print '成功的更新了'.$num.'条记录; } }catch (PDOException $e){ die('操作失败'.$e->getMessage()); } ?>
The following error occurs when running:
Parse error: syntax error, unexpected '操作失败' (T_STRING) in D:\xp.cn\www\wwwroot\admin\localhost_80\wwwroot\pdoupdatepre.php on line 28
Please solve it?
The prompt is very clear, syntax error: there is an extra "}" in line 17, delete