Reputation: 1
$qry = "SELECT * FROM nl_lang_var";
if($qry === false)
{
$sql = "INSERT INTO nl_lang_var set value='$value' WHERE name='$var' and langid=$langid"; }
else {
echo "already existed"; }
I want to know if the table nl_lang_var exists or not.
If it doesn't exist it must insert, otherwise give message.
Upvotes: 1
Views: 105
Reputation: 110
There are 2 possible solutions.
Solution 1
SELECT 1 FROM nl_lang_var WHERE 1 LIMIT 1;
If the above query returns no error then table exists.
Solution 2
SELECT *
FROM information_schema.TABLES
WHERE TABLE_SCHEMA = 'DB_NAME' AND TABLE_NAME = 'nl_lang_var';
Upvotes: 1
Reputation: 1374
Try this query
SHOW TABLES LIKE 'nl_lang_var';
Or
SHOW TABLE STATUS LIKE 'nl_lang_var';
SHOW TABLE is fater than information_schema
But both are depended on the privileges to the connected user
Upvotes: 0
Reputation: 1442
i havent tried it if this will work, but i hope you can get some idea
SELECT count(table_name)
FROM INFORMATION_SCHEMA.TABLES
WHERE table_name = 'nl_lang_var'
Upvotes: 0