Forums

SQL Query (2 posts)

  1. shaf
    Member
    Posted 3 years ago #

    Hi

    I am using the $wpdb to carry out SQL queries. I am trying to write a query that will allow me to see all the tables in the database but I keep getting an unknown database error. See code below:

    $sql  = "SHOW TABLES FROM " . '$wpdb';
    if (!$result = mysql_query($sql))
    {
    	die ('Error getting table list (' . $sql . ' :: ' . mysql_error() . ')');
    }
  2. slars
    Member
    Posted 3 years ago #

    Shaf,

    Try this query instead:

    $sql = "SHOW TABLES";

    Your connect string should already connect you to the MySQL DB and you should have a database string which defines which database to act upon. "SHOW TABLES" is a basic sql statement to show all tables in your current database.

    Steve

Topic Closed

This topic has been closed to new replies.

About this Topic