2

Can any one give The Example php code for connecting and getting a sql stored proceedure

A-K
  • 16,804
  • 8
  • 54
  • 74
Linto P D
  • 8,839
  • 7
  • 30
  • 39

2 Answers2

1

what do you prefer to use? Here is an example taken from php.net:

$mysqli = new mysqli("localhost", "my_user", "my_password", "world");

/* check connection */
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}

$query  = "CALL get_items(1, @param1, @param2); "; 

/* execute multi query */
if ($mysqli->multi_query($query)) {
    do {
        /* store first result set */
        if ($result = $mysqli->store_result()) {
            while ($row = $result->fetch_row()) {
                printf("%s\n", $row[0]);
            }
            $result->free();
        }
        /* print divider */
        if ($mysqli->more_results()) {
            printf("-----------------\n");
        }
    } while ($mysqli->next_result());
}

/* close connection */
$mysqli->close();

remember, that you have to free the resultset, if you do not, you will get an error while executing a next query.

Before I know something about mysqli, I apply mysqli to handle sp's. Just take a look at the follwing example:

$rs = mysql_query("CALL get_items(1, @param1, @param2); ");
$rs = mysql_query("SELECT @param1, @param2" );
while($row = mysql_fetch_assoc($rs))
{
    print_r($row); 
}
Tobias Bambullis
  • 736
  • 5
  • 17
  • 45
0

Calling a Stored procedure with PDO

Phill Pafford
  • 83,471
  • 91
  • 263
  • 383