Link to home
Start Free TrialLog in
Avatar of darren-w-
darren-w-Flag for United Kingdom of Great Britain and Northern Ireland

asked on

Handling two tables from a PDO Call to a MS SQL Procedure

HI,

I have a procedure call to a MS SQL DB, the procedure returns two tables, how should I handle the tables, I'm quite able to deal with one. I'm doing it with 2 single calls at present but the page takes too long to call.

My get tables method:

 
public function getTables($procname,$parameter) {
      //see : http://www.php.net/manual/en/pdo.prepared-statements.php example #10 and #11
      $vars = explode(",", $parameter);
      $num = count($vars);
      //create holders for calls
      for ($i = 0; $i <= $num; $i++) {
         $holder.="?";
         if ($i != $num)
         {
            $holder.=",";
         }
      }
//var_dump($holder);
//var_dump($vars );
      $stmt = DBO::prepare("EXECUTE " . $procname . " " . $holder);
      // TODO build bind, may need to change type for strings and ints and others
      // perhaps look to put into dbcalls
      for ($i = 0; $i <= $num; $i++) {
         $stmt->bindParam($i + 1, $vars[$i], PDO::PARAM_STR | PDO::PARAM_INPUT_OUTPUT, 4000);
      }

// call the stored procedure
      try
      {
        $stmt->execute();
      } catch (PDOException $e)
      {
//echo "\nPDO::errorCode(): ";
//print $dbh->errorCode();
         var_dump($e);
         // var_dump($e);
      }
      $data = ($stmt->fetchAll(PDO::FETCH_ASSOC));
      $stmt->closeCursor();
     // var_dump($data);
      return $data;
   }

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Richard Quadling
Richard Quadling
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of darren-w-

ASKER

Thats great, thanks.
Coming back to this, and it looks like the MSSQL driver does not support this feature?
@Darren, you may be running an older version of the driver.

http://msdn.microsoft.com/en-us/library/ff628153(SQL.90).aspx