Created
October 15, 2013 00:55
-
-
Save AVDW/6984896 to your computer and use it in GitHub Desktop.
PHP - Connecting to and executing a stored procedure in an SQL server.
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
$serverName = "value.cloudapp.net"; | |
$connectionInfo = array( "Database"=>"value", "UID"=>"value", "PWD"=>"value"); | |
$conn = sqlsrv_connect( $serverName, $connectionInfo); | |
if( $conn === false ) | |
{ | |
echo "Could not connect.\n"; | |
print('<pre>'); | |
die( print_r( sqlsrv_errors(), true)); | |
print('</pre>'); | |
} | |
/*--------- The next few steps call the stored procedure. ---------*/ | |
/* Define the Transact-SQL query. Use question marks (?) in place of | |
the parameters to be passed to the stored procedure */ | |
$tsql_callSP = "{call InsertUser(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}"; | |
/* Define the parameter array. By default, the first parameter is an | |
INPUT parameter. The second parameter is specified as an INOUT | |
parameter. Initializing $vacationHrs to 8 sets the returned PHPTYPE to | |
integer. To ensure data type integrity, output parameters should be | |
initialized before calling the stored procedure, or the desired | |
PHPTYPE should be specified in the $params array.*/ | |
//$date = date_create('2000-01-01'); | |
$date = '01-01-2000'; | |
echo $date; | |
$Title = 'value'; | |
$FirstName = 'value'; | |
$MiddleName = 'value'; | |
$LastName = 'value'; | |
$Gender = 'value'; | |
$DOB = $date; | |
$Email = 'value'; | |
$Phone = 'value'; | |
$Mobile = 'value'; | |
$ResidentialAddress = 'value'; | |
$ResidentialPostCode = 'value'; | |
$ResidentialSuburb = 'value'; | |
$ResidentialState = 'value'; | |
$ResidentialCountry = 'value'; | |
$PostalAddress = 'value'; | |
$PostalPostCode = 'value'; | |
$PostalSuburb = 'value'; | |
$PostalState = 'value'; | |
$PostalCountry = 'value'; | |
$BrowserDetails = 'value'; | |
$IsActive = 1; | |
$Password = 'value'; | |
$Salt = 'value'; | |
$LastLogin = $date; | |
$CompanyID = null; | |
$Created = $date; | |
$CreatedBy = 'value'; | |
$LastModified = $date; | |
$LastModifiedBy = 'value'; | |
$Username = 'value'; | |
$UserRole = 'value'; | |
$params = array( | |
array($Title, SQLSRV_PARAM_IN), | |
array($FirstName, SQLSRV_PARAM_IN), | |
array($MiddleName, SQLSRV_PARAM_IN), | |
array($LastName, SQLSRV_PARAM_IN), | |
array($Gender, SQLSRV_PARAM_IN), | |
array($DOB, SQLSRV_PARAM_IN), | |
array($Email, SQLSRV_PARAM_IN), | |
array($Phone, SQLSRV_PARAM_IN), | |
array($Mobile, SQLSRV_PARAM_IN), | |
array($ResidentialAddress, SQLSRV_PARAM_IN), | |
array($ResidentialPostCode, SQLSRV_PARAM_IN), | |
array($ResidentialSuburb, SQLSRV_PARAM_IN), | |
array($ResidentialState, SQLSRV_PARAM_IN), | |
array($ResidentialCountry, SQLSRV_PARAM_IN), | |
array($PostalAddress, SQLSRV_PARAM_IN), | |
array($PostalPostCode, SQLSRV_PARAM_IN), | |
array($PostalSuburb, SQLSRV_PARAM_IN), | |
array($PostalState, SQLSRV_PARAM_IN), | |
array($PostalCountry, SQLSRV_PARAM_IN), | |
array($BrowserDetails, SQLSRV_PARAM_IN), | |
array($IsActive, SQLSRV_PARAM_IN), | |
array($Password, SQLSRV_PARAM_IN), | |
array($Salt, SQLSRV_PARAM_IN), | |
array($LastLogin, SQLSRV_PARAM_IN), | |
array($CompanyID, SQLSRV_PARAM_IN), | |
array($Created, SQLSRV_PARAM_IN), | |
array($CreatedBy, SQLSRV_PARAM_IN), | |
array($LastModified, SQLSRV_PARAM_IN), | |
array($LastModifiedBy, SQLSRV_PARAM_IN), | |
array($Username, SQLSRV_PARAM_IN), | |
array($UserRole, SQLSRV_PARAM_IN) | |
); | |
/* Execute the query. */ | |
$stmt3 = sqlsrv_query( $conn, $tsql_callSP, $params); | |
if( $stmt3 === false ) | |
{ | |
echo "Error in executing statement 3.\n"; | |
die( print_r( sqlsrv_errors(), true)); | |
} | |
/*Free the statement and connection resources. */ | |
sqlsrv_free_stmt($stmt3); | |
sqlsrv_close($conn); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment