Fatal error: Call to undefined function sqlsrv_connect()

Fatal error: Call to undefined function sqlsrv_connect()

There are mostly two php.ini changes files located, in my case, for wamp or xampp server.
One is simple change under the php custom folder changes and the other changes one is in the path of C:\wamp\bin\apache\Apachex.x.x\bin folder.
When connecting to SQL database through sqlsrv_connect used this function,
we are referring to simple the php.ini file in the apache folder.

Add the following php latest version (as per your version) to this file:

extension=c:/wamp/bin/php/php5.4.16/ext/php_sqlsrv_53_ts.dll

PHP Config File Check

Use this simple script to check the your php version:

<?php echo phpinfo(); ?>

Step by Step (call to undefined function sqlsrv_connect() xampp)

Step 1

Download SQLSRV32.EXE (Microsoft Drivers for PHP for SQL Server) from: http://www.microsoft.com/en-us/download/details.aspx?id=20098

Step 2

Choose path: C:\xampp\php\ext

Step 3

simple Uncomment or Append extension = php_sqlsrv_56_ts.dll in php.ini

Step 4

Last step to Restart Apache from XAMPP or wamp server Control Panel (Stop/Start)

Load the simple PHP drivers in php.ini file and restart the server.

extension=php_sqlsrv_53_ts.dll
extension=php_pdo_sqlsrv_53_ts.dll

SQL Connection Simple way

<?php
$serverName = "200.225.289.248, 1433"; //serverName\instanceName, portNumber (default is 1433)
$connectionInfo = array( "Database"=>"pakainfo", "UID"=>"sa", "PWD"=>"[email protected]");
$conn = sqlsrv_connect( $serverName, $connectionInfo);

if( $conn ) {
    // echo "Connection established.<br />";
}else{
	echo "<pre>";
     echo "Connection could not be established.<br />";
     die( print_r( sqlsrv_errors(), true));
	 echo "</pre>";
}

?>

SQL Query

$query="select * from pakainfo where mst_id=1";
$stmt = sqlsrv_query( $conn, $query );
$data=array();
while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC) ) {
    $data[]=$row;
}

Example


Related FAQ

Here are some more FAQ related to this Article:

  1.   PHP Get Current URL Full Path HTTP-HTTPS Protocol
  2.   Jquery Count Child Elements with class
  3.   Laravel 5.8 active menu item using request
  4.   Convert CSV File Into JSON using PHP
  5.   cannot be loaded because running scripts is disabled on this system
  6.   How To Import CSV File into MySQL using PHP
  7.   PHP Laravel MySQL Joins Tutorial with Examples
  8.   Top 10 Best PHP Code Optimization Techniques
  9.   jQuery Form Validator Script
  10.   Shorthand comparisons using PHP Ternary Operator