0

I have a problem with my php application.This is running on pp 5.2 and mysql 5.6

When I try to run this

    <?php
$dbname ='LAA-dbname';

if (!mysql_connect('mysq123.php.server', 'LAAuser', 'mypwd')) {
    echo 'Could not connect to mysql';
    exit;
}

$sql = "SHOW TABLES FROM $dbname";
$result = mysql_query($sql);

if (!$result) {
    echo "DB Error, could not list tables\n";
    echo 'MySQL Error: ' . mysql_error();
    exit;
}

while ($row = mysql_fetch_row($result)) {
    echo "Table: {$row[0]}\n";
}

mysql_free_result($result);
?>

I am getting this error

DB Error, could not list tables MySQL Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-dbname' at line 1

What can be the reason? Thanks

4

1 回答 1

0

尝试这个

  $sql = "SHOW TABLES FROM `$dbname`";

您必须使用反引号让 mysql 知道该表是LAA-dbname其他明智的,它将被理解为减号。

于 2013-06-19T17:56:10.140 回答