创建PDO对象时,php中出现意外的等号

时间:2014-11-11 21:00:26

标签: php mysql pdo

的config.php

<?php
    try{
        connection = new PDO("mysql:dbname=9lessons;host=localhsot", "root", "");
    }catch(PDOException $error){
        echo $error->getMessage();
    }
?>

main.php

<?php
    include ('config.php');
    foreach ($connection->query('SELECT * FROM message LIMIT 9') as $row)
    {
        $msg = $row['msg'];
        $mes_id=$row['mes_id'];
        $up=$row['up'];
        $down=$row['down'];
 ?>
<div class="main">
<div class="box1">
<div class="up">
<a href=""class="vote" id="<?php echo $mes_id?>" name="up">
<?php echo $up; ?></a></div>

<div class="down">
<a href="" class="vote" id="<?php echo $mes_id; ?>" name="down">
<?php echo $down; ?></a></div>
</div>
<div class="box2"><?php echo $msg; ?></div>
</div>

<?php } ?>

当我运行上面的代码时,我收到如下错误消息:

Parse error: syntax error, unexpected '=' in C:\xampp\htdocs\config.php on line 3

1 个答案:

答案 0 :(得分:3)

变量以$开头:

$connection = new PDO("mysql:dbname=9lessons;host=localhsot", "root", "");

任何时候你有Parse error: syntax error, unexpected - 找到意想不到的东西并慢慢回溯寻找语法错误。