douzhongqiu5032 2014-11-25 01:45
浏览 224
已采纳

无法在mysql数据库中查询表,mysqli_query返回false

I have just started learning php and i am trying to set up connection to local mysql db I have pasted the code that i am trying to run.

I am getting $result = false and i reach else part --" No return" In the image attached , there is a table called "table" under db test, and i have 3-4 entries as well

image-snapshot

Can someone take time to help me understand whats going wrong here ?

thank you !!

<!doctype html>
<html>  
    <head>
    </head>
    <body>
         <?php
            $link = mysqli_connect('localhost','root','','test'); 
            $query = "select * from 'table' " ;


            $outputDisplay = "";
            $myrowcount = 0;
                if (!$link) 
                { 
                    die('Could not connect to MySQL: ' . mysqli_error()); 
        } else 
            {
                echo 'Connection OK'; 
                print ($query);
                $result = mysqli_query($link, $query);

                if($result)
                {
                                        $numresults = mysqli_num_rows($result);
                    printf("Select returned %d rows.
", $numresults);
                }
                else
                {
                    echo "No return";
                }
                mysqli_close($link); 
            }
         ?>
    </body>

</html>
  • 写回答

2条回答 默认 最新

  • doumisha5081 2014-11-25 01:57
    关注

    mysqli_query() returns false because something wrong has happened in your query..Here your problem is with the single quotes..Instead of single quotes you should use back-ticks like

            $query = "select * from `table` " ;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥30 关于#opencv#的问题:使用大疆无人机拍摄水稻田间图像,拼接成tif图片,用什么方法可以识别并框选出水稻作物行
  • ¥15 Python卡尔曼滤波融合
  • ¥20 iOS绕地区网络检测
  • ¥15 python验证码滑块图像识别
  • ¥15 根据背景及设计要求撰写设计报告
  • ¥20 能提供一下思路或者代码吗
  • ¥15 用twincat控制!
  • ¥15 请问一下这个运行结果是怎么来的
  • ¥15 单通道放大电路的工作原理
  • ¥30 YOLO检测微调结果p为1