php文件解析错误

标签 php mysql

<分区>

我已经开始制作一个应用程序,可以将数据从网站检索到应用程序。我制作了一个简单的 php 文件,但它给了我错误:

Parse error: syntax error, unexpected '$con' (T_VARIABLE) in /srv/disk10/2052804/www/poolswag.co.nf/service.php on line 5

我在网上查了一下,但遇到同样错误的人注意到他们少了一个分号,而我的有一个分号

任何帮助将不胜感激

    <?php
     
    // Create connection
   -----> line 5 $con=mysqli_connect("http://www.poolswag.co.nf/","2052804_swag”,”test5350”,”2052804_swag");
     
    // Check connection
    if (mysqli_connect_errno())
    {
      echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }
     
    // This SQL statement selects ALL from the table 'Locations'
    $sql = "SELECT * FROM PoolInfo";
     
    // Check if there are results
    if ($result = mysqli_query($con, $sql))
    {
        // If so, then create a results array and a temporary one
        // to hold the data
        $resultArray = array();
        $tempArray = array();
     
        // Loop through each row in the result set
        while($row = $result->fetch_object())
        {
            // Add each row into our results array
            $tempArray = $row;
            array_push($resultArray, $tempArray);
        }
     
        // Finally, encode the array to JSON and output the results
        echo json_encode($resultArray);
    }
     
    // Close connections
    mysqli_close($con);
    ?>

最佳答案

你看到弯引号/弯引号 了吗?

("http://www.poolswag.co.nf/","2052804_swag”,”test5350”,”2052804_swag")
                                           ^ ^        ^ ^

这就是导致错误的原因。

("http://www.poolswag.co.nf/","2052804_swag","test5350","2052804_swag")

完全是两种不同的动物。

您可能从网上复制了一些可能编码不正确的代码,或者正在使用某种类型的文字处理器而不是代码“编辑器”。

有关一些代码编辑器和添加信息的列表,请参阅以下内容:

关于php文件解析错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35258149/

相关文章:

javascript - 在html中使用放大镜将鼠标悬停在图像上

php - 使用 PHP 将推荐数量和推荐 ID 添加到 MySQL 数据库中

php - 执行此搜索和替换模板的更好方法

mysql - 在 MySQL 中的最后一个 INSERT 上执行 SELECT 或将数据插入到 2 个表中,这些表具有由 MySQL 自动生成的公共(public)列

java - 以非常小的插入将大量数据插入数据库

PHP : select multiple count(id) from MySQL as one query

php - 从mysql日期字段中获取基于日和月的数据

javascript - 图表.js 2.0 : How to change title of tooltip

php - 用PHP实现Rabin-Karp算法

php - 从 Magento 中的发票 pdf 中删除运输方式和付款方式