Created
February 25, 2017 15:34
-
-
Save REPTILEHAUS/ee2426fdfde7209c70def50396fea6b0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| $dsn = "mysql:host=localhost;dbname=storedprocedures;charset=utf8;"; //change to your hosts IP and database name | |
| $user = 'root'; //database username | |
| $pass = ''; //database password | |
| //PDO Error Exceptions added to to the connection string below | |
| $options = array(PDO::ATTR_ERRMODE =--> PDO::ERRMODE_EXCEPTION); | |
| try { | |
| $dbh = @new PDO($dsn, $user, $pass, $options) | |
| // The ID we feed to the stored procedures INPUT :usersession the OUTPUT variable that related to this ID is stored in the user variable @output_name. | |
| $id = 4; | |
| $stmt = $dbh->prepare("CALL getMemeber_sproc(:usersession, @output_name)"); | |
| $stmt->bindParam(':usersession', $id); | |
| // execute the stored procedure CALL | |
| $stmt->execute(); | |
| // fetch the output | |
| $outputArray = $dbh->query("select @output_name")->fetch(PDO::FETCH_ASSOC); | |
| print "procedure returned " . $outputArray['@output_name'] . "\n"; | |
| } catch(PDOException $e) { | |
| $e->getMessage(); | |
| } | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment