donglanfu5831 2015-07-10 15:18
浏览 179

Mysql表示表不存在。 可能有什么不对?

I am having trouble retrieving records from a table in a chemical structures database I am creating with php. Whenever I use either mysql_query() or mysqli_query() the result always equals false because of the error (Table 'Crystal_Structs.BinaryCompoundList' doesn't exist) which I was told by mysqli_error().

I know the table exists and is working when I use SHOW TABLES and the CHECK TABLE queries as the table is displayed and its status is seen as okay. I am able to run Select, Insert, etc queries in both my Netbeans IDE database service area and the command line. I'm not sure what's going on but any help is greatly appreciated. Thank you.

Code Snippet:

    /* Connect to local MySQL server */
$localdb = mysqli_connect("server", "user", "pass")
    or die("Unable to connect to Database Server");

/*Connect to Crystal Structures db*/
mysqli_select_db($localdb, "Crystal_Structs")
        or die(mysqli_error($localdb));
session_start();
$Ab=$_POST['compound'];
$spce_grp=$_POST['space_group'];

$query = 'SELECT * FROM BinaryCompoundList '
        . 'WHERE compound="$_SESSION[Ab]" '
        . 'AND space_group="$_SESSION[spce_grp]"';

$result = mysqli_query($localdb, $query);

if($result == false){
    echo 'not a proper query:';
    echo $query;
    die(mysqli_error($localdb)); /*debug*/
}
$check = mysqli_num_rows($result);
if($check != 1){
    die("Multiple Records");
}

SHOW TABLES query:

+---------------------------+
| Tables_in_Crystal_Structs |
+---------------------------+
| BinaryCompoundList        |
| BinaryCompoundSites       |
+---------------------------+
2 rows in set (0.00 sec)

CHECK TABLE BinaryCompoundList query:

+------------------------------------+-------+----------+----------+
| Table                              | Op    | Msg_type | Msg_text |
+------------------------------------+-------+----------+----------+
| Crystal_Structs.BinaryCompoundList | check | status   | OK       |
+------------------------------------+-------+----------+----------+
1 row in set (0.00 sec)
  • 写回答

1条回答 默认 最新

  • dongxieyou3314 2015-07-10 15:29
    关注

    I noticed you are calling your db by two names: Crystal_Structs in the code and Crystal_Structures in your error message. Any chance you have created multiple db's along the dev path?

    Other than that, must be a typo, can you show the output for SHOW TABLES?

    评论

报告相同问题?

悬赏问题

  • ¥15 C++ yoloV5改写遇到的问题
  • ¥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()实现黑框里写入与删除?