0

我正在使用这个 php 代码来提取我创建的测试表中的列标题。但是,每当我尝试运行代码时,它都会给我这个错误:There was an error running the query [Table 'meta_test.information_schema' doesn't exist]从我在网上看到的信息看来,我的代码应该可以工作,但这是我第一次尝试这样的事情。这是我的代码:

    $camp = $_POST['campaign'];
    $query = "SELECT COLUMN_NAME FROM INFORMATION_SCHEMA WHERE TABLE_NAME = '$camp'";

    try{
        if(!$result = $db->query($query)){
            die('There was an error running the query [' . $db->error . ']');
        }

        echo "<pre>";
        print_r($result);
        echo "</pre>";
    }catch(exception $e){
        echo $e;
    }
4

1 回答 1

1

您需要指定表名:

SELECT COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = '$camp'
于 2013-06-24T20:29:18.113 回答