{"id":78934,"date":"2026-11-10T19:42:58","date_gmt":"2026-11-10T19:42:58","guid":{"rendered":"http:\/\/bangla.sitestree.com\/?p=78934"},"modified":"2026-11-10T19:55:32","modified_gmt":"2026-11-10T19:55:32","slug":"rewritten-sql-server-70089","status":"publish","type":"post","link":"http:\/\/bangla.sitestree.com\/?p=78934","title":{"rendered":"Calling SQL Server Stored Procedures from PHP: Modern Drivers and Examples"},"content":{"rendered":"<p>Early PHP applications commonly used mssql_connect, mssql_init, and mssql_bind. Those functions belonged to an obsolete extension and should not be copied into a new application.<\/p>\n<h2>Choose a supported driver<\/h2>\n<p>For PHP with Microsoft SQL Server, evaluate the Microsoft Drivers for PHP for SQL Server (SQLSRV or PDO_SQLSRV), matching PHP, operating system, and SQL Server versions.<\/p>\n<h2>Example: SQLSRV stored procedure call<\/h2>\n<pre><code>$connection = sqlsrv_connect($server, [\n  \"Database\" =&gt; \"TrainingDB\",\n  \"UID\" =&gt; getenv(\"DB_USER\"),\n  \"PWD\" =&gt; getenv(\"DB_PASSWORD\")\n]);\nif ($connection === false) { throw new RuntimeException(\"Connection failed\"); }\n$id = 17;\n$params = [[$id, SQLSRV_PARAM_IN]];\n$stmt = sqlsrv_query($connection, \"{CALL dbo.GetCustomer(?)}\", $params);\nif ($stmt === false) { throw new RuntimeException(\"Query failed\"); }\nwhile ($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) {\n    echo htmlspecialchars((string)$row[\"CustomerName\"], ENT_QUOTES, \"UTF-8\");\n}\nsqlsrv_free_stmt($stmt);\nsqlsrv_close($connection);<\/code><\/pre>\n<h2>Procedure contract<\/h2>\n<p>The example assumes dbo.GetCustomer accepts an integer parameter. For output parameters and result sets, consult the current driver documentation, since binding directions and buffer types matter.<\/p>\n<h2>Security essentials<\/h2>\n<p>Use least-privilege accounts, encrypted connections with valid certificates, and server-side input validation. Never return raw database error details to website visitors.<\/p>\n<hr\/>\n<p><strong>AI, sources and reuse:<\/strong> This is an AI-generated rewrite informed by <a href=\"https:\/\/bangla.sitestree.com\/?p=70089\">the original Open Education post (#70089)<\/a>, with additional explanations and examples. The new article text may be copied, adapted, and republished with or without a reference to this site. Third-party resources and trademarks keep their own rights. <strong>AI can make mistakes.<\/strong> Verify version support, code correctness, and security practices against Microsoft documentation, and test with nonproduction data first.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Early PHP applications commonly used mssql_connect, mssql_init, and mssql_bind. Those functions belonged to an obsolete extension and should not be copied into a new application.<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":true,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_hide_featured_image":false,"_jetpack_featured_image_duplicate_dismissed":0,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[20,182],"tags":[466],"class_list":["post-78934","post","type-post","status-publish","format-standard","hentry","category-information-technology","category---blog","tag-sql-server","item-wrap"],"jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":78935,"url":"http:\/\/bangla.sitestree.com\/?p=78935","url_meta":{"origin":78934,"position":0},"title":"PHP Functions for SQL Server: Historical MSSQL APIs and Supported Replacements","author":"Sayed","date":"November 10, 2026","format":false,"excerpt":"A historic PHP API family exposed functions beginning with mssql_, including connection management, result fetching, stored-procedure execution, and metadata inspection. That API is no longer suitable for modern PHP applications.","rel":"","context":"In &quot;Information Technology&quot;","block_context":{"text":"Information Technology","link":"http:\/\/bangla.sitestree.com\/?cat=20"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":26207,"url":"http:\/\/bangla.sitestree.com\/?p=26207","url_meta":{"origin":78934,"position":1},"title":"PHP SQL Server Stored Procedure #Root","author":"Author-Check- Article-or-Video","date":"April 19, 2021","format":false,"excerpt":"\/* prepare the statement resource *\/ $stmt=mssql_init(\"your_stored_procedure\", $conn); \/* now bind the parameters to it *\/ mssql_bind($stmt, \"@id\", $id, SQLINT4, FALSE); mssql_bind($stmt, \"@name\", $name, SQLVARCHAR, FALSE); mssql_bind($stmt, \"@email\", $email, SQLVARCHAR, FALSE); \/* now execute the procedure *\/ $result = mssql_execute($stmt); Another Example $conn = mssql_connect($db_host,$db_user,$db_password);if ($conn===false){ echo 'Cannot connect.'; exit;\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":78950,"url":"http:\/\/bangla.sitestree.com\/?p=78950","url_meta":{"origin":78934,"position":2},"title":"Migrating Legacy PHP SQL Server Stored Procedure Code to Supported Drivers","author":"Sayed","date":"November 10, 2026","format":false,"excerpt":"Older PHP tutorials used the obsolete mssql_* extension for SQL Server procedure calls. A modern rewrite should preserve the application behaviour while changing the database access layer.","rel":"","context":"In &quot;Information Technology&quot;","block_context":{"text":"Information Technology","link":"http:\/\/bangla.sitestree.com\/?cat=20"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":16205,"url":"http:\/\/bangla.sitestree.com\/?p=16205","url_meta":{"origin":78934,"position":3},"title":"PHP SQL Server Stored Procedure","author":"Sayed","date":"September 21, 2019","format":false,"excerpt":"\/* prepare the statement resource *\/ $stmt=mssql_init(\"your_stored_procedure\", $conn); \/* now bind the parameters to it *\/ mssql_bind($stmt, \"@id\", $id, SQLINT4, FALSE); mssql_bind($stmt, \"@name\", $name, SQLVARCHAR, FALSE); mssql_bind($stmt, \"@email\", $email, SQLVARCHAR, FALSE); \/* now execute the procedure *\/ $result = mssql_execute($stmt); Another Example $conn = mssql_connect($db_host,$db_user,$db_password);if ($conn===false){ echo 'Cannot connect.'; exit;\u2026","rel":"","context":"In &quot;\u09ac\u09cd\u09b2\u0997 \u0964 Blog&quot;","block_context":{"text":"\u09ac\u09cd\u09b2\u0997 \u0964 Blog","link":"http:\/\/bangla.sitestree.com\/?cat=182"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":70089,"url":"http:\/\/bangla.sitestree.com\/?p=70089","url_meta":{"origin":78934,"position":4},"title":"PHP SQL Server Stored Procedure #16","author":"Author-Check- Article-or-Video","date":"August 25, 2021","format":false,"excerpt":"\/* prepare the statement resource *\/$stmt=mssql_init(\"your_stored_procedure\", $conn);\/* now bind the parameters to it *\/mssql_bind($stmt, \"@id\", $id, SQLINT4, FALSE);mssql_bind($stmt, \"@name\", $name, SQLVARCHAR, FALSE);mssql_bind($stmt, \"@email\", $email, SQLVARCHAR, FALSE); \/* now execute the procedure *\/$result = mssql_execute($stmt); Another Example $conn = mssql_connect($db_host,$db_user,$db_password);if ($conn===false){ echo 'Cannot connect.'; exit;} if (mssql_select_db(\"YourDatabase\",$conn) === false) { echo\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":78969,"url":"http:\/\/bangla.sitestree.com\/?p=78969","url_meta":{"origin":78934,"position":5},"title":"Calling SQL Server Stored Procedures from Modern PHP: A Migration Tutorial","author":"Sayed","date":"November 10, 2026","format":false,"excerpt":"Old PHP code often used mssql_init, mssql_bind and mssql_execute. Those APIs are obsolete, but their basic goal\u2014calling a SQL Server stored procedure with typed parameters\u2014remains common.","rel":"","context":"In &quot;Information Technology&quot;","block_context":{"text":"Information Technology","link":"http:\/\/bangla.sitestree.com\/?cat=20"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"jetpack_featured_media_url":"","_links":{"self":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/78934","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=78934"}],"version-history":[{"count":1,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/78934\/revisions"}],"predecessor-version":[{"id":78996,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/78934\/revisions\/78996"}],"wp:attachment":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=78934"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=78934"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=78934"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}