gpt4 book ai didi

php - 如何通过使用 MYSQL 和 Codeigniter 来获取删除表时的返回值?

转载 作者:行者123 更新时间:2023-11-29 21:26:20 25 4
gpt4 key购买 nike

我正在尝试使用 CI3.0.4 中的方法为此过程创建表,我想检查表dropcreate、set <之后的返回值强>外键或不?

只有当我尝试删除表但该表不存在于数据库中时,该函数才能检查 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;
}

}
}

?>

感谢帮助

最佳答案

试试这个

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;
}
}

我希望它对你有用。

关于php - 如何通过使用 MYSQL 和 Codeigniter 来获取删除表时的返回值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35487551/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com