MySQL table exists on the server but cannot be accessed from PHP

I added a new table to the database using PHPMyAdmin; when trying to access it from a PHP page, I get the dreaded MySQL "table does not exist" error.
The database connection data is fine, it uses multiple rows above on one page to access another table in the same database. If I do SHOW TABLES

in PHPMyAdmin, then a new table is displayed; if I do it from a PHP page, the new table doesn't appear in the list. The mechanism for the new table is MyISAM, like all other tables in the database. I can only access the db server through 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();
}

      

+3


source to share


3 answers


On Unix, table names are case sensitive. This is not the case on Windows. Fun, isn't it? Actually, like their respective file systems. Do you think this is a coincidence?

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



Field names are not case sensitive.

For database and table names, this depends on the underlying operating system. Identifier ID sensitivity

+4


source


The answer is simple: some typo or some other silly mistake: you are connecting to the wrong server, editing the wrong file, or something like that. Just double check everything.
There is no particular mistake to cause this



+2


source


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

To solve this problem, you can wrap the fields and table name with heavy accents ('), for example:

SELECT 'value' FROM 'pivot';

      

0


source







All Articles