douchu4048 2018-09-09 07:09
浏览 649
已采纳

如何在“SELECT TABLE_NAME FROM information_schema.TABLES”中使mysql“num_rows”工作?

$query_Recordset4 = sprintf("SELECT TABLE_NAME FROM information_schema.TABLES 
 WHERE TABLE_SCHEMA='message' and TABLE_NAME like '1a%nd5'");
 $Recordset4 = mysql_query($query_Recordset4, $messageconnection);
 $totalRows_Recordset4 = mysql_num_rows($Recordset4);

I ran SQL query about SELECT TABLE_NAME FROM information_schema.TABLES WHERE TABLE_SCHEMA='message' and TABLE_NAME like '1a%nd5' in PhpMyAdmin. It revealed "2" total rows.

However, I queried the answer "mysql_num_rows" in php was "0". Doesn't "mysql_num_rows" work in SELECT TABLE_NAME FROM information_schema.TABLES? What is the alternative method?

If a alternative method is below content. $query_Recordset5 = sprintf("SELECT COUNT(*) FROM information_schema.TABLES WHERE TABLE_SCHEMA='message' and TABLE_NAME like '$colname_Recordset6' "); $row_Recordset5 = mysql_fetch_assoc($Recordset5);

The result of "mysql_fetch_assoc" revealed nothing, but it worked in other mysql_query. How can I solve this problem?

  • 写回答

3条回答 默认 最新

  • dongyou2279 2018-09-09 07:54
    关注

    Your problem is actually in your call to sprintf, it is trying to process %n as a conversion specification. You need to change the % in that string to %% i.e.

    $query_Recordset4 = sprintf("SELECT TABLE_NAME FROM information_schema.TABLES WHERE TABLE_SCHEMA='message' and TABLE_NAME like '1a%%nd5'");
    

    You should also switch from using mysql_ functions to mysqli_ as the mysql functions have been deprecated as of PHP5.5 and removed as of PHP7 due to bugs in the code.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥50 三种调度算法报错 采用的你的方案
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥15 对于这个问题的解释说明
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败