Question

I have a problem with my Codeigniter appclication at work. I'm using a virtual Windows Server 2008 R2, IIS, MSSQL and PHP

When I try to insert new records in the database, I get the following warning (for each insert):

A PHP Error was encountered

Severity: Warning

Message: array_shift() expects parameter 1 to be array, null given

Filename: sqlsrv/sqlsrv_driver.php

Line Number: 423

The code I'm using:

$data = array(
                'DataTypeSpecification'         => $dataTypeSpecID,
                'DocumentCode'                  => $docCode,
                'Title'                         => $title,
                'ProjectCode'                   => $projectCode, 
                'Process'                       => $process, 
                'Author'                        => $author,
                'Status'                        => $status,
                'Version'                       => $version, 
                'DateApproval'                  => $dateApproval,
                'Medium'                        => $medium, 
                'PaperArchivedDate'             => $paperArchivedDate, 
                'DMSArchivedDate'               => $DMSArchivedDate,
                'EDocDocument'                  => $eDocDocument,
                'Wildcard'                      => $wildcard, 
                'SequentialNumber'              => $seqNumber, 
                'Location'                      => $location, 
                'ArchivedShelf'                 => $archivedShelf,
                'Container'                     => $container, 
                'Remarks'                       => $remakrs, 
                'APDProjectStatus'              => $APDProjectStatus, 
                'SelectedForIND'                => $selectedForIND);

$result = $this->db->insert('dbo.ProjectRecords', $data);
return $result;

All of the variables are set correctly. Here is the funny thing. It seems that everything gets inserted correctly in the database...

Anyone knows why this warning is displayed?

Regards Nicolai

Was it helpful?

Solution

So, I had to edit the driver itself. I changed the file system/database/sqlsrv/sqlsrv_driver.php The two functions _error_message() (line 407) and _error_number() (line 423)

In both of them, i changed the first two lines to:

$tmp = sqlsrv_errors();
if($tmp == null) return null;
$error = array_shift($tmp);

So that i.e. _error_number() becomes:

function _error_number()
{
    $tmp = sqlsrv_errors();
    if($tmp == null) return null;
    $error = array_shift($tmp);
    return isset($error['SQLSTATE']) ? $error['SQLSTATE'] : null;
}

The error occurs since sqlsrv_errors() returns NULL, and when passing NULL to the array_shift() method, baaad things happens!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top