1

I have php with connect to SQL Server.

<?php
$serverName = "AC-CLOUD"; //serverName\instanceName
$connectionInfo = array( "Database"=>"DataSEAS", "UID"=>"sa", "PWD"=>"Masterkey2010", "CharacterSet"  => "UTF-8");
$conn = sqlsrv_connect( $serverName, $connectionInfo);

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

$sql = "SELECT sc.Id as Id, sc.Code, sc.Name, sc.Specification, sc.Specification2, sc.X_Specification3, f.Name as firma_Name FROM StoreCards sc
left join firms f on f.id = sc. X_pozicane_u ";

$stmt = sqlsrv_query( $conn, $sql );

if( $stmt === false) {
    die( print_r( sqlsrv_errors(), true) );
}

When I connected it with fastcgi, it is working fine, but now I need to connect it with Apache and it isn't working with this code. When I tried another php code with Apache, or phpinfo, it's working fine, but this connect to db with apache, doesn't work. Can you help me?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Martin Jašek
  • 77
  • 1
  • 2
  • 9

2 Answers2

1

Call to undefined function sqlsrv_connect() error means that sqlsrv module hasn't been loaded, you should edit your .ini file and add sqlsrv to the extensions

This pages shows the example of iis express but you can see how to load sqlsrv dll s in your .ini

https://www.microsoft.com/en-us/sql-server/developer-get-started/php/windows/step/2.html

Genjutsu
  • 223
  • 2
  • 12
0

going by the information in the comments, your apache mod_php installation doesn't have the SQLSRV extension installed, but your php-fpm installation does. instructions on installing it can be found here: http://php.net/manual/en/sqlsrv.setup.php

hanshenrik
  • 19,904
  • 4
  • 43
  • 89