Nickel
Nickel

Reputation: 55

MySQL table exists on server but cannot access it from PHP

I added to a database a new table using PHPMyAdmin; when trying to access it from a PHP page I get the dreaded MySQL error "table doesn't exist".
Database connection data are OK, they are used a few lines above on the same page to access another table in the same database. If I do SHOW TABLES in PHPMyAdmin the new table is listed; if I do it from a PHP page the new table does not appear in the list. Engine for the new table is MyISAM, like all other tables in the database. I can access the db server only via PHPMyAdmin.

Sorry, I forgot the code, here it is:

$db = mysql_connect ($db_host, $db_user, $db_password) or 
die("Error message here");
$db_select = mysql_select_db($db_name, $db)or die("Error message here");


$query = ("SELECT * FROM `old_table`");
$result = mysql_query($query);
while ($row = mysql_fetch_array($result)) 
{
// do stuff - here it works
}


$query = ("SELECT * FROM  `new_table`");
$result = mysql_query($query);
while ($row = mysql_fetch_array($result)) 
{
// do stuff - here it does not work
echo mysql_error();
}

Upvotes: 4

Views: 2307

Answers (3)

Walber
Walber

Reputation: 11

The answer is: the table name or at least one of the field names is a reserved word.

To solve it, you can enclose the fields and table name with grave accents (`), e.g:

SELECT `value` FROM `pivot`;

Upvotes: 1

Your Common Sense
Your Common Sense

Reputation: 157895

The answer is simple: some typo or another silly mistake like this: you're connecting wrong server, editing wrong file or something of the kind. Just double check everything.
There is no particular error to cause this

Upvotes: 2

Techie
Techie

Reputation: 45124

On Unix, table names are case sensitive. On Windows, they are not. Fun, isn't it? Kinda like their respective file systems. Do you think it's a coincidence?

It probably depends on table type; MyISAM in your case.

Field names are case-insensitive regardless.

For database and table names, it depends on the underlying operating system. Identifier Case Sensitivity

Upvotes: 4

Related Questions