/*
$table = table be will deleted
$pk_value = pk of register will be deleted
*/
public function allow_delete($table, $pk_value){
$model = new CI_Model();
$model->db->select("table_name");
$model->db->select("column_name");
$model->db->from("information_schema.key_column_usage");
$model->db->where("referenced_table_name", $table);
$query = $model->db->get ();
if ($query->num_rows () == 0) {
return true;
}
$tables = $query->result ();
foreach ($tables as $table){
$model = new CI_Model();
$model->db->select("*");
$model->db->from($table->table_name);
$model->db->where($table->column_name, $pk_value);
$query = $model->db->get ();
if ($query->num_rows () > 0) {
return false;
}
}
return true;
}
Check foreignkey before delete using Codeigniter and MySql
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.