Welcome Guest, Not a member yet? Register   Sign In
Executing MYSQL Stored Procedures
#1

[eluser]bhakti.thakkar[/eluser]
Hi all,
i have created a SP and created successfully (MYSQL 5.0.45)
now i want to execute that SP in CI. i read somewhere in this forum that you have to use mysqli instead of mysql driver and for that i even changed the line in database.php as below:
Code:
function db_connect()
    {
    define("CLIENT_MULTI_RESULTS",131072);//Enable/disable multi-results
    define("CLIENT_MULTI_STATEMENTS",65536);//Enable/disable multi-statement support
        
    return @mysql_connect($this->hostname, $this->username, $this->password, TRUE,CLIENT_MULTI_STATEMENTS);
    }

and also have changed the database setting to this: $db['default']['pconnect'] = FALSE;
and run the script:

$sql=" call colavg('Task_T' , 'EstimatedHours_DC')";
$rs= $this->db->query($sql);
//print $rs;


and i still get the error :

Code:
A Database Error Occurred
Error Number: 1312

PROCEDURE mydb.colavg can't return a result set in the given context

call colavg('Task_T' , 'EstimatedHours_DC')

please help
#2

[eluser]jaRguS[/eluser]
i have the same question. Please help
#3

[eluser]bgreene[/eluser]
$sql=”select colavg(‘Task_T’ , ‘EstimatedHours_DC’)”;
$rs= $this->db->query($sql);
#4

[eluser]jipod[/eluser]
I also have some problem ... hiks..
but a sample stored procedure i tried call and can get results, this code like this :

Code:
<?php
class Sp extends Model {
    
    function __construct()
    {
        parent::Model();
    }
    

    function sp_jual_in()
    {
        //post data
        $vnojual = "001";
        $vtgljual = "2010-08-01";
        $voutlet = "out001";
        $vkdrokok = "02";
        $vbal = 1;$vpres = 2;$vbks = 3;
        
        
        $query = " CALL sp_jual_in(?, ?, ?, ?, ?, ?, ?) ";
        
        //the data to replace
        $data = array(
            $vnojual,
            $vtgljual,
            $voutlet,
            $vkdrokok,
            $vbal,
            $vpres,
            $vbks
        );
        
        $result = $this->db->query($query, $this->safe_escape($data));
        $data = "";
        
       foreach($result->result_array() as $row)
       {
            $data.= $row['vnojual']."<br />\r\n";
       }
      
       return $data;
    }
    
    //escapes and adds single quotes
    //to each value of an array
    function safe_escape(&$data)
    {
        if(count($data) <= 0)
        {
            return $data;
        }
        
        foreach($data as $node)
        {
            $node = $this->db->escape($node);
        }
        
        return $data;
    }

}
?&gt;

but after I echo this result, I get some errors like this !!!

Quote:A Database Error Occurred

Error Number: 2014

Commands out of sync; you can't run this command now
#5

[eluser]safarath[/eluser]
the below forum will help you!!

http://ellislab.com/forums/viewthread/179001/
#6

[eluser]bijufun[/eluser]
@jipod : hey ! i also get this error while i was trying to check user login. When the sql find the records it don't give any error. But when the sql finds no records, it pop out same error.

And I try to solve the problem as mentioned by "safarath". But its not solving my error.

Please help !!




Theme © iAndrew 2016 - Forum software by © MyBB