views:

31

answers:

2

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

A: 

Calling a Stored procedure with PDO

Phill Pafford
can you demonstrate a simple example code, please
Linto P D
The link above has a ton of example code, Did you visit the link?
Phill Pafford
+1  A: 

hi

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); 
}

Greets from Germany ;-)

Tobias Bambullis