Tutorial by Examples

$dbServer = "localhost,1234"; //Name of the server/instance, including optional port number (default is 1433) $dbName = "db001"; //Name of the database $dbUser = "user"; //Name of the user $dbPassword = "password"; //DB Password of that user $connectionI...
//Create Connection $conn = sqlsrv_connect($dbServer, $connectionInfo); $query = "SELECT * FROM [table]"; $stmt = sqlsrv_query($conn, $query); Note: the use of square brackets [] is to escape the word table as it is a reserved word. These work in the same way as backticks ` do in ...
To call a stored procedure on the server: $query = "{call [dbo].[myStoredProcedure](?,?,?)}"; //Parameters '?' includes OUT parameters $params = array( array($name, SQLSRV_PARAM_IN), array($age, SQLSRV_PARAM_IN), array($count, SQLSRV_PARAM_OUT, SQLSRV_PHPTYPE_INT) //$cou...
$conn = sqlsrv_connect($dbServer, $connectionInfo); $query = "SELECT * FROM [users] WHERE [name] = ? AND [password] = ?"; $params = array("joebloggs", "pa55w0rd"); $stmt = sqlsrv_query($conn, $query, $params); If you plan on using the same query statement more...
There are 3 main ways to fetch results from a query: sqlsrv_fetch_array() sqlsrv_fetch_array() retrieves the next row as an array. $stmt = sqlsrv_query($conn, $query); while($row = sqlsrv_fetch_array($stmt)) { echo $row[0]; $var = $row["name"]; //... } sqlsrv_fetch...
When a query goes wrong, it is important to fetch the error message(s) returned by the driver to identify the cause of the problem. The syntax is: sqlsrv_errors([int $errorsOrWarnings]); This returns an array with: KeyDescriptionSQLSTATEThe state that the SQL Server / OBDC Driver is incodeThe S...

Page 1 of 1