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条)

报告相同问题?

悬赏问题

  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害