0 レビュー
1 回答
php-CodeigniterでMYSQLを使用してテーブルがドロップされたときに戻り値を取得するにはどうすればよいですか?
このプロセスでCI3.0.4のメソッドを使用してテーブルを作成しようとしています。テーブルがドロップ、作成、設定された後の戻り値を確認したい<強い>外部キーかどうか?
この関数は、テーブルを削除しようとしたときにdropがtrueの場合にのみチェックできますが、そのテーブルはデータベースに存在しません。 drop()は引き続きtrueを返します
<?php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class Dbforges extends Main_Controller
{
public $respond = array();
protected $column = '';
public function __construct()
{
parent::__construct();
$data = array(
"fid" => "bigint(50) AUTO_INCREMENT,",
"fk_c_id" => "bigint(50),",
"fk_group_id" => "bigint(50),",
"fk_user_id" => "bigint(50),",
"fk_product_id" => " bigint(50),",
"feaddata" => " decimal(10,2) NOT NULL,",
"credit" => "decimal(10,2) NOT NULL,",
"b_debit" => "decimal(10,2) NOT NULL,",
"b_credit" => "decimal(10,2) NOT NULL,",
"description" => " varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,",
"PRIMARY KEY" => "(`fid`),",
"KEY `fk_c_id` " => "(`fk_c_id`),",
"KEY `fk_group_id` " => "(`fk_group_id`),",
"KEY `fk_user_id` " => "(`fk_user_id`),",
"KEY `fk_product_id` " => "(`fk_product_id`)"
);
if ($this->drop("feadback") == false) {
$this->respond[] = 'nod';
} else {
$this->respond[] = 'd';
}
if ($this->AddTables("feadback", $data) == false) {
$this->respond[] = 'noc';
} else {
$this->respond[] = 'c';
}
if ($this->Add_Foreignkey("feadback", "fk_c_id", "cat", "c_id") == false) {
$this->respond[] = 'nfk';
} else {
$this->respond[] = 'fk';
}
echo json_encode(array("res"=>$this->respond));
}
public function index()
{
}
public function AddTables($table, $data)
{
if (!empty($table) && !empty($data)) {
foreach ($data as $k => $col) {
$this->column .= $k . ' ' . $col;
}
if ($this->db->query("CREATE TABLE IF NOT EXISTS $table ($this->column) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT= 0;") == true) {
return true;
} else {
return false;
}
}
}
protected function drop($table = false)
{
if ($table) {
if ($this->db->query("DROP TABLE IF EXISTS $table;") == true) ;
return true;
} else {
return false;
}
}
public function Add_Foreignkey($fkTable, $fk, $refTables, $referal)
{
if ($this->db->query("ALTER TABLE $fkTable ADD CONSTRAINT $fkTable.$fk FOREIGN KEY ($fk) REFERENCES `$refTables` ($referal) ON DELETE CASCADE ON UPDATE CASCADE;") == true) {
return true;
} else {
return false;
}
}
}
?>
助けてくれてありがとう
わからない
0
レビュー
答え :
解決策:
これを試してください
public function drop($table = false)
{
if ($table) {
if ($this->db->query("DROP TABLE IF EXISTS $table;") == true){
$query = $this->db->query("SHOW TABLES LIKE '".$table."'");
if($query->num_rows() != null)
{
return true;
}
else{
return false;
}
}
}
else
{
return false;
}
}
私はあなたのためにその仕事を願っています。
わからない
同様の質問
私たちのウェブサイトで同様の質問で答えを見つけてください。