duanlu5055 2012-08-23 16:44
浏览 47

如何使用pdo检查表是否存在[重复]

Possible Duplicate:
MySQL check if a table exists without throwing an exception

Basically I have my MySQL dbname = test and my table name = page.

I want to create a query using a php PDO to check if the table "page" exists in my db "test"

I've tried this but it doenst work.. it always tells me that it doesnt exists.. even when it does

if (array_search('pages',$db->query('show tables')->fetch()) !== false) { echo "the db exists";

    } else { echo "the db doesnt exists";
    // Create tableS
    //$IDB->execute();
    }
  • 写回答

1条回答 默认 最新

  • dongxiaoguang9108 2012-08-23 16:50
    关注

    there is no predefined test for existing table in PDO, you must do :

    $pdo = new PDO($dsn,$user,$pass,$options);
    $results = $pdo->query('SHOW TABLE LIKE \'page\'');
    if(count($results)>0){echo 'table exists';}
    
    评论

报告相同问题?

悬赏问题

  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思