/** * Function removes all records in child table with no parent records * Table names must be in SQL notation without placeholder. * @param string $child_table Name of table for removing records. * @param string $child_foreign_key Name of field in child table with parent record id * @param string $parent_table Name of table with parent records. * @param string $parent_primary_key primary key in parent table, if empty will be equal $child_foreign_key */ function db_remove_missing_records($child_table, $child_foreign_key, $parent_table, $parent_primary_key = '') { if ($parent_primary_key == '') { $parent_primary_key = $child_foreign_key; } Database::query("DELETE FROM ?:{$child_table} WHERE {$child_foreign_key} NOT IN (SELECT {$parent_primary_key} FROM ?:{$parent_table})"); }
public function __construct($config) { Db::$raw = true; if (!Db::getField("SHOW TABLES LIKE '?:cache'")) { Registry::set('runtime.database.skip_errors', true); Db::$raw = true; $res = Db::query('CREATE TABLE ?:cache (name varchar(255), company_id int(11) unsigned not null default \'0\', data mediumtext, expiry int, tags varchar(255), PRIMARY KEY(name, company_id), KEY (tags), KEY (name, company_id, expiry), KEY (company_id)) Engine=MyISAM DEFAULT CHARSET UTF8'); Registry::set('runtime.database.skip_errors', false); if ($res == false) { throw new DatabaseException('Database cache data storage is not supported. Please choose another one.'); } } parent::__construct($config); return true; }