0

I want to connect to mssql server so I've use unixodbc and POD driver. now when i execute insert query i want last inserted_id so I've use PDO function lastInsertId() , and it is giving me error.

PHP Fatal error: Uncaught PDOException: SQLSTATE[IM001]: Driver does not support this function: driver does not support lastInsertId().

googling for hours i found solution to use, SELECT SCOPE_IDENTITY() as id, this didn't help me it is giving me error.

PHP Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 0 [Microsoft][ODBC Driver 13 for SQL Server]Connection is busy with results for another command

Can Anyone help me solve my problem? I want to get last inserted id

My PHP code is on linode server and my DB is MSSQL.

This is my insert function.

$resultOFP=$objDaMS->ManupulateData("INSERT INTO Offline_Patient 
(doctorid,firstname,lastname,mobile1,email,createdon,hsbit,clinicid) VALUES (?,?,?,?,?,?,?,?) ",
array($DocID,$User_on_detail[0]['firstname'],$User_on_detail[0]['lastname'],
$User_on_detail[0]['mobile1'],$User_on_detail[0]['email'],date('Y-m-d H:i:s'),true,$AddId));

And this is my ManupulateData() function.

public function ManupulateData($query,$val=array()){
        $stmt = $this->db->prepare($query);
        for($i=0;$i<count($val);$i++){
            $stmt->bindParam($i+1, $val[$i],PDO::PARAM_STR);
        }
        $stmt->execute();
        if($this->queryDriver=="mssql"){
            //$stmt->closeCursor();
            return $this->db->query('SELECT SCOPE_IDENTITY() as id');
            //return $this->db->lastInsertId(PDO::FETCH_ASSOC);
        }
        else{
            return $this->db->lastInsertId(PDO::FETCH_ASSOC);
        }
    }

Seriously Need Help.

Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
Archish
  • 850
  • 8
  • 32

0 Answers0