Regarding Stored procedure in php code

Discussion in 'PHP' started by nanna_vijayalaxmi, Dec 7, 2007.

  1. #1
    Hi all ,
    I need small help regarding calling the stored procedures in to PHP code.Actually i am able to getting values if i wrote code in the same php page, with multiple stored procedures calls.But when i call those stored procedures in functions which is in another page I am facing the problem and didn't get any error but i got warning like following

    [Sat Dec 08 11:31:10 2007] [error] [client 127.0.0.1] PHP Warning: mysqli::multi_query() [<a href='function.mysqli-multi-query'>function.mysqli-multi-query</a>]: Couldn't fetch mysqli in D:\\Program Files\\PHPSoftwares\\PHPSoftwares\\ApacheWebServer\\htdocs\\govind\\databaseFunction_03-12-07.php on line 78


    and also I wrote code like following


    $mysqli = new mysqli("localhost", "root", "", "vijaya");
    $res_new=array();
    $Query1="";$Query="";$result1=0;
    $url="sciencedaily.com";
    $Query1="call GetExpert_last('$url')";
    echo $Query1;
    echo "<br/>";
    $res = $mysqli->query("$Query1");
    if(mysqli_num_rows($res)>0)
    {
    $row = mysqli_fetch_row($res);
    $res = $row[0];
    $res_new[] = $row[0];
    $res_new[] = $row[1];
    $mysqli->close();
    $Query="call GetExpert_lastvalue($res)";
    echo $Query;echo "<br/>";
    $result1=5;
    $result1=$mysqli->query("$Query");
    echo "hai";echo "<br/>";
    echo $result1;
    if(mysqli_num_rows($result1)>0)
    {
    $expert_value= mysqli_fetch_row($result1);
    $res_new[]=$expert_value[0];
    $res_new[]=$expert_value[1];
    $res_new[]=$expert_value[2];
    } else
    $res_new[]="None";

    }

    for($i=0;$i<count($res_new);$i++)
    {
    $strid= $res_new["$i"];
    echo $strid;
    echo "<br/>";
    }
     
    nanna_vijayalaxmi, Dec 7, 2007 IP
  2. Kaizoku

    Kaizoku Well-Known Member

    Messages:
    1,261
    Likes Received:
    20
    Best Answers:
    1
    Trophy Points:
    105
    #2
    If its in a function your need to make the string a global.
     
    Kaizoku, Dec 7, 2007 IP
  3. nanna_vijayalaxmi

    nanna_vijayalaxmi Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    hi, thank you for your message.But in this example first stored procedure is executed and return value but i didn't get value by calling second storedprocedure
     
    nanna_vijayalaxmi, Dec 7, 2007 IP
  4. Kaizoku

    Kaizoku Well-Known Member

    Messages:
    1,261
    Likes Received:
    20
    Best Answers:
    1
    Trophy Points:
    105
    #4
    You really need to indent and wrap your codes.

    I found a syntax error
    
    } else
    $res_new[]="None";
    
    }
    
    Code (php):
    should be
    
    } else {
    	$res_new[]="None";
    
    }
    
    Code (php):
     
    Kaizoku, Dec 7, 2007 IP
  5. satusaja

    satusaja Active Member

    Messages:
    108
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #5
    You are mistaken Kaizoku. The original code is correct. The closing curly bracket is for the earlier if statement:

    if(mysqli_num_rows($res)>0)

     
    satusaja, Dec 7, 2007 IP
  6. Kaizoku

    Kaizoku Well-Known Member

    Messages:
    1,261
    Likes Received:
    20
    Best Answers:
    1
    Trophy Points:
    105
    #6
    And that is why people should indent and wrap their codes, really hard to read like this :eek:
     
    Kaizoku, Dec 8, 2007 IP
  7. nanna_vijayalaxmi

    nanna_vijayalaxmi Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Hi,

    Thanks for ur reply,

    We also tried the way as you suggested by placing braces for else condition,but we are still getting the same warning message.We are facing problem while fetching results for the call of stored porcedure inside the second function.
     
    nanna_vijayalaxmi, Dec 9, 2007 IP