0

CIでsqlsrvドライバーを使用していますが、$ this-> db-> insert_id()を使用すると、配列が返されます。

私はdb挿入後にコントローラーでこれを行っています

エラー番号:42S22

[Microsoft] [SQL Server Native Client 11.0][SQLServer]無効な列名'アレイ'。

誰でも助けることができますか?どうもありがとう

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

$dataにはID列は含まれていません。これは私が現在使用しているコードですが、まだ$last_idから配列を取得しています。

4

1 に答える 1

2

それ以外の :

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;

これは暫定的な解決策です。

于 2013-06-20T14:05:12.240 に答える