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

Also Read :  Generate XML Save File Using PHP And MySQL database

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"=>"pakainfo@123");
$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

Also Read :  jQuery Ajax GET & POST REQUEST Methods PHP MySQLi

Leave a Reply

Your email address will not be published. Required fields are marked *