Post by justinesmithies » Fri Mar 22, 2013 4:00 am

I need to test if the table customer_online exists and i will act accordingly depending on the answer yes or no.
I made this function which works great if the table exists but if i delete the c from customer to simulate it not existing i get this error instead of my tpl page being rendered.
Notice: Error: Table 'OpenCart-Test.oc_ustomer_online' doesn't exist Error No: 1146 SELECT * FROM oc_ustomer_online in /home/justine/www/opencart-test/opencart-1.5.5.1/upload/system/database/mysql.php on line 50

Code: Select all

public function CheckCustomer(){
$query = $this->db->query('SELECT * FROM '.DB_PREFIX.'customer_online');
return $query->row;
}
Can anyone help me with this so i can test if it does exist or not without the errors ??

Thanx
Justine


This fixed it in my controller file.

Code: Select all

$this->data['checkcustomer'] = @mysql_query ('SELECT * FROM '.DB_PREFIX.'customer_online');

User avatar

Posts

Joined
Sun Dec 23, 2012 5:31 am

Post by arnisraido » Tue Sep 27, 2016 6:16 am

Try this one:

Code: Select all

$result = $this->db->query("SHOW TABLES LIKE '" . DB_PREFIX . "mytablename'");
if((boolean)$result->num_rows) {
    // this means - Table with that name - does not exists:
    // ...
}
from:
http://stackoverflow.com/a/9008326/1720476
http://stackoverflow.com/a/25206039/1720476

Newbie

Posts

Joined
Mon Aug 27, 2012 11:24 pm
Who is online

Users browsing this forum: No registered users and 45 guests