SQL Server Driver for PHP Cheat Sheet

Several of my recent posts have focused on how to use the SQL Server Driver for PHP in various ways. You might think that I would know the driver API by heart at this point, but alas, my many trips back to the documentation are proof that my brain is like a fixed length queue – if something new goes in, something else must go out. So, I’ve created a cheat sheet that saves me some of those trips to the documentation. I’m hoping that others might find it helpful too. It really is only helpful is you are familiar with the API – it just provides enough clues to jog your memory. Attached to this post is a printable PDF version of the sheet, and I would be happy to modify it based on feedback. If there are things you would find more useful than what is on the sheet now, please let me know.

I’ll call out a few things about this sheet to hopefully make it more usable:

  • The signatures for the driver functions are included, but I haven’t included type information for the parameters. For more details about the function signatures, see the API Reference.

  • The SQLTYPE constants are used when you want to specify SQL Server data types when inserting data into a database. For examples of how to do this, see How to: Specify SQL Server Data Types. Also note that these constants give you clues about the syntax for declaring data types in SQL Server: by dropping the "SQLSRV_SQLTYPE_" prefix, you have the proper database syntax.

  • The PHPTYPE constants are used when you want to specify PHP data types when retrieving data from a database. For examples of how to do this, see How to: Specify PHP Data Types.

  • The FETCH constants are used when you want to specify whether a row is retrieved as numeric or associative array (by default, sqlsrv_fetch_array returns an array with both numeric and associative indexes). For examples, see How to: Retrieve Data as an Array.

  • The CURSOR constants are used when you want to specify the type of cursor that is used to consume a result set (by default, a forward-only cursor is used). Note that the sqlsrv_num_rows function requires a static or keyset cursor. For more information, see sqlsrv_query or sqlsrv_prepare.

  • The right-hand margin includes commonly used database functions that can be called in Transact-SQL code. For details about these functions, see SQL Server Functions.

And here’s the cheat sheet (also attached as a PDF)…


I hope this proves helpful.



Share this on Twitter


Comments (0)

Skip to main content