MySQL Forums
Forum List  »  PHP

Re: How do you call a stored procedure from PHP ...
Posted by: Peter Brawley
Date: March 02, 2006 09:49AM

Here's an example that had been posted to the sproc forum. A 5.0.18 server has a sys db where we keep utility stored procedures, including this simple one ...

CREATE PROCEDURE ShowTables( IN dbname CHAR(64) )
BEGIN
SELECT
table_name,
engine,
version,
table_collation AS collation,
table_rows AS rows
FROM information_schema.tables
WHERE table_schema=dbname;
END;

And here's a simple PHP page which calls it. Change USR & PWD to appropriate values for your setup. If you prefer mysql_connect(), make the 4th param 0 and the 5th param 65536 (see the PHP docs).

<html><body>
<?php

$conn = mysql_pconnect( "localhost", "USR", "PWD", 65536 )
or die( "Failed to connect to MySQL server" );
mysql_select_db( "test", $conn ) or die( "Could not select test database" );
$result = mysql_query( "CALL sys.ShowTables('bench')" )
or die( mysql_error() );
$rows = mysql_num_rows( $result );
echo "Rows=$rows<br/>";
?>
</body></html>

Options: ReplyQuote




Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.