SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot txt3rob's Avatar
    Join Date
    Jul 2013
    Location
    Liverpool UK
    Posts
    199
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PDO - Check if table exists.

    Hi guys,

    I need help on a clean way to check if a table exists.

    I want to set a variable based on if the table exists or not or if it does and it's empty set $dbnum to 0

    My Current Query is :

    PHP Code:
    $dbnumbers $db->prepare('SELECT * FROM '.$tablename.'');
    $dbnumbers->execute();
    $count $dbnumbers->rowCount();
    if (
    $count == 0) {
    $dbnum "0";
    } else {
    $dbnum $count;


  2. #2
    SitePoint Evangelist N9ne's Avatar
    Join Date
    Aug 2002
    Location
    UK
    Posts
    596
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    SHOW TABLES LIKE \'' . $tablename . '\'

  3. #3
    SitePoint Zealot txt3rob's Avatar
    Join Date
    Jul 2013
    Location
    Liverpool UK
    Posts
    199
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Cheers dude will try this now


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •