SQL Server最后在CodeIgniter中插入id返回数组 [英] SQL Server last insert id return array in CodeIgniter
本文介绍了SQL Server最后在CodeIgniter中插入id返回数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在CI
中使用sqlsrv驱动程序但是,当我使用$ this-> db-> insert_id()它返回一个数组
我在数据库插入后在控制器中执行此操作
错误号码:42S22
< [SQL Server Native Client 11.0] [SQL Server]列名称为Array无效。
任何人都可以帮助?
感谢alot
模型
function insert_message($ data)
{
$ this-> db-> insert('message',$ data);
$ last_id = $ this-> db-> insert_id();
return $ last_id;
}
Controller
$ message = $ this-> Message-> insert_message(
$ data = array(
'admin_account_id'=> ; $ accountid,
'message_subject'=> $ subject,
'message_content'=> $ content,
'message_priority'=> $ priority,
'date_send' => $ date_send,
'message_status'=> $ status,
'message_createddate'=> date(Ymd H:i:s),
'message_send_usergroup'=> ; $ usergroup
);
);
数据库驱动程序(sqlsrv_driver.php)
函数insert_id()
{
return $ this-> query @@ IDENTITY as insert_id') - > row('insert_id');
}
$ data不包括标识列。
这是我现在使用的代码,但我仍然从$ last_id获取数组。
解决方案
而不是:
return $ this-> db-> insert_id
您将替换为:
$ query = $ this-> db-> query(SELECT IDENT_CURRENT('< table_name>')as last_id);
$ res = $ query-> result();
return $ res [0] - > last_id;
这是临时解决方案。
i'm using sqlsrv driver in CI However, when i use the $this->db->insert_id() it returns me an array
I'm doing this in the controller after a db insert
Error Number: 42S22
[Microsoft][SQL Server Native Client 11.0][SQL Server]Invalid column name 'Array'.
Anybody can help? Thanks alot
Model
function insert_message($data)
{
$this->db->insert('message', $data);
$last_id = $this->db->insert_id();
return $last_id;
}
Controller
$message = $this->Message->insert_message(
$data = array(
'admin_account_id' => $accountid,
'message_subject' => $subject,
'message_content' => $content,
'message_priority' => $priority,
'date_send' => $date_send,
'message_status' => $status,
'message_createddate' => date("Y-m-d H:i:s"),
'message_send_usergroup'=> $usergroup
);
);
Database driver (sqlsrv_driver.php)
function insert_id()
{
return $this->query('select @@IDENTITY as insert_id')->row('insert_id');
}
the $data does not include the identity column. This is the code i'm using now but i'm still getting an Array from $last_id.
解决方案
Instead of :
return $this->db->insert_id();
you would replace with :
$query = $this->db->query("SELECT IDENT_CURRENT('<table_name>') as last_id");
$res = $query->result();
return $res[0]->last_id;
This is a provisional solution.
这篇关于SQL Server最后在CodeIgniter中插入id返回数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文