Welcome Guest, Not a member yet? Register   Sign In
CodeIgniter and SQLSRV Driver.
#1

[eluser]adanyc[/eluser]
Hi guys, I'm having many problems in code igniter and I would like u could help me.
I have the following stored procedure created in SQL Server 2008.
Code:
CREATE PROCEDURE [dbo].[USP_CODEIGNITER_DEMO]        
@nAreId INT=NULL,
@cAreDescripcion VARCHAR(100)=NULL,
@error VARCHAR(100) OUTPUT        
AS        
BEGIN TRANSACTION          
BEGIN TRY
  BEGIN
   UPDATE AREA SET cAreDescripcion=@cAreDescripcion WHERE nAreId=@nAreId          
  END
            
  SET @error ='exito'          
  COMMIT TRANSACTION          
END TRY          

BEGIN CATCH          
ROLLBACK TRANSACTION          
SET @error =ERROR_MESSAGE()          
END CATCH

This stored make an update in one table I have.

My PHP code is this:
Code:
function update_usuarios() {      
        $nAreId='767';
        $cAreDescripcion='mydescripcion';
        $error = ""; // I tested it whith null also
        $query = $this->db->query("USP_CODEIGNITER_DEMO ?,?,?", array(
            $nAreId,
            $cAreDescripcion,
            $error
                ));        
        return $error;
    }

In my view I only wanna print my output resul from my sql stored procedure, of 'exito' or 'error' from my action.

I give u my model code too:
Code:
function index() {
        $data['datax'] =   $this->usuarios_model->update_usuarios();
        $this->load->view('usuarios_view', $data);
    }

Sorry 4 my bad english, I'm from Peru.
Thanxs 4 all.
I hope ur help.
CYA
#2

[eluser]NotDior[/eluser]
I've done one thing with CodeIgniter and SQL Server 2008 with a stored procedure and here's how I did things ( from what you pasted in here it looks like you might have a few things incorrect ).

My controller looks like:

Code:
public function search() {
        $aSearch = $this->input->post();
        
        unset($aSearch['btnSubmit']);

        $sSearchText = '';
        $sSearchText .= $aSearch['txtKeywords'];

        $sSearchText .= " doctype:".$aSearch['rblDocumentType'];
        if (!empty($aSearch['ddlStoryType'])) {
            $sSearchText .= " storytype:".$aSearch['ddlStoryType'];
        }
        $sSearchText .= " headline:".$aSearch['txtHeadline'].']';
        $sSearchText .= " reporter:".$aSearch['txtReporter'].']';
        $sSearchText .= " sortby:".$aSearch['rblSortBy'];

        if (!empty($aSearch['fromdate']) && (!empty($aSearch['todate']))) {
            $sSearchText .= " fromdate:".$aSearch['fromdate'];
            $sSearchText .= " todate:".$aSearch['todate'];
        }

        
        $aData['results'] = $this->Archivemodel->search($sSearchText);
        $aData['articlecount'] = count($aData['results']);
        $aData['searchparams'] = $sSearchText;
        $this->load->view('results',$aData);
        
    }



My model looks like:

Code:
public function searchDB($sText) {
        $sSelect = "EXEC dbo.spSearch @text=?";
        $xResult = $this->db->query($sSelect,array($sText));
        if ($xResult->result_array()) {
            return ($xResult->result_array());
        } else {
            return(FALSE);
        }
    }
#3

[eluser]adanyc[/eluser]
Hi friend.
Thank u for your time. Im gonna test your method.
But I'd like u or someone else post another alternative solution for my problem but using my code. Please note i'm using OUTPUT parameters in SQL sever and I wanna get and show results of them in the view.
See u.
Thnxs a lot.
#4

[eluser]adanyc[/eluser]
[quote author="NotDior" date="1346792530"]I've done one thing with CodeIgniter and SQL Server 2008 with a stored procedure and here's how I did things ( from what you pasted in here it looks like you might have a few things incorrect ).

My controller looks like:

Code:
public function search() {
        $aSearch = $this->input->post();
        
        unset($aSearch['btnSubmit']);

        $sSearchText = '';
        $sSearchText .= $aSearch['txtKeywords'];

        $sSearchText .= " doctype:".$aSearch['rblDocumentType'];
        if (!empty($aSearch['ddlStoryType'])) {
            $sSearchText .= " storytype:".$aSearch['ddlStoryType'];
        }
        $sSearchText .= " headline:".$aSearch['txtHeadline'].']';
        $sSearchText .= " reporter:".$aSearch['txtReporter'].']';
        $sSearchText .= " sortby:".$aSearch['rblSortBy'];

        if (!empty($aSearch['fromdate']) && (!empty($aSearch['todate']))) {
            $sSearchText .= " fromdate:".$aSearch['fromdate'];
            $sSearchText .= " todate:".$aSearch['todate'];
        }

        
        $aData['results'] = $this->Archivemodel->search($sSearchText);
        $aData['articlecount'] = count($aData['results']);
        $aData['searchparams'] = $sSearchText;
        $this->load->view('results',$aData);
        
    }



My model looks like:

Code:
public function searchDB($sText) {
        $sSelect = "EXEC dbo.spSearch @text=?";
        $xResult = $this->db->query($sSelect,array($sText));
        if ($xResult->result_array()) {
            return ($xResult->result_array());
        } else {
            return(FALSE);
        }
    }
[/quote]


I tested your solution and I get this error, what it means?

Code:
A Database Error Occurred

Error Number: 01000

[Microsoft][SQL Server Native Client 10.0][SQL Server]Ejecutando SQL directamente, sin cursor.

EXEC dbo.USP_CODEIGNITER_DEMO @nAreId='767',@cAreDescripcion='paaaaaaaaxxxxx',@error='oooooo'

Filename: C:\xampp\htdocs\demoCodeIgniter_bd\system\database\DB_driver.php

Line Number: 330
#5

[eluser]NotDior[/eluser]
It's been awhile since I've taken any spanish but I believe it's saying there's an error with your cursors in the SQL statement.

Again I've only done one project like this, so I'm not of much help other than what I was able to get to work.

Regards,
Christian




Theme © iAndrew 2016 - Forum software by © MyBB