PHP到SQL查询失败

时间:2018-11-12 23:31:59

标签: php sql mysqli

虽然连接正常;但是,查询失败。我正在使用AMMPS,括号和MySQL。有人可以测试一下,让我知道吗,因为我已经尝试了所有方法,但都失败了。该代码旨在用作博客。

<?php
        $con= new mysqli("localhost", "phpblog");
        // Check connection
        if (mysqli_connect_errno())
          {
          echo "Failed to connect to MySQL: " . mysqli_connect_error();
          }
        else{
            echo "Connection successful.";
        }

        $sql= "SELECT id FROM Post";
        //$result=mysqli_query($con,$sql);
        //$result=mysqli->query($sql);


        /*if (mysqli_num_rows($result) > 0) {
            echo "There is data in the table.";
            }
        else {
            echo "0 results";
        }*/

        /* Select queries return a resultset */
        if ($result = $con->query(sql)) {
            //printf("Select returned %d rows.\n", mysqli_num_rows($result));
            echo "Query succeeded";
            /* free result set */
            mysqli_free_result($result);
            }else{
                echo "Query failed.";
            }
        // Fetch all
        //mysqli_fetch_assoc($result);

        mysqli_close($con);
        ?>

0 个答案:

没有答案