NetTalk Central

Author Topic: PHP MS Sql connection error  (Read 7051 times)

MyBrainIsFull

  • Full Member
  • ***
  • Posts: 134
    • View Profile
PHP MS Sql connection error
« on: February 24, 2016, 08:15:11 PM »
Hi all
I have 3 pcs on my network
A - MS Sql server
B - a MS Server 2008 SP2 with IIS & PHP installed
C - a MS Server 2008 with no iis - but has NTalk server

both B & C have a desktop app that can read the Ms Sql data on "A", so firewall is OK

I can get B & C to do simple php things, so php works,  and  with phpinfo.php  I can see a section for "SQLSRV"   so I believe the MS driver is installed on both as php_sqlsrv_54_nts.dll  in the ext folder,  and extension set in php.ini for this path.

But I cant access the MsSql data from either B or C  using simple connection strings I have Googled to test the connection,  I get a an error "Connection could not be established"

Has anyone been able to connect to MS Sql ?   Any hints would be appreciated.
Thanks

                             PLEASE NOTE
THERE IS BEER AVAILABLE TO WHOEVER SOLVES THIS


-------[ Using SqlSrv_connect()  shows echo 2 then throws error...
-------[ Using MsSql_connect()  DOES NOT show echo 2 - it just plain dies

<?php
$serverName = "192.168.0.121,1433";        
//$serverName = "s2003";         //serverName\instanceName

$connectionInfo = array( "Database"=>"BCDS_WMS", "UID"=>"sa", "PWD"=>"password");

 // $conn = mssql_connect( $serverName, $connectionInfo);
$conn = sqlsrv_connect( $serverName, $connectionInfo);

echo " <br> 2..";

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

==================[ UPDATE ]=========
Following the Googles I read it might need odbc installed, so I did and using odbc_connect( )   - this works OK  - but still cant connect with sqlsrv_connect( )    which I need to use (to use customers php code)

<?php
$virtual_dsn = 'DRIVER={SQL Server};SERVER=s2003;DATABASE=BCDS_Wms';
$connection = odbc_connect($virtual_dsn,'sa','password') or die('ODBC Error:: '.odbc_error().' :: '.odbc_errormsg().' :: '.$virtual_dsn);

if ($connection){     echo "Good <p>" }

# query the users table for name and surname
$query = "SELECT id,barcode FROM Asset";

# perform the query
$result = odbc_exec($connection, $query);

# fetch the data from the database
while(odbc_fetch_row($result) ){
  $id    = odbc_result($result, 1);
  $bcd = odbc_result($result, 2);

  print("id=$id   barcode $bcd<br>"); $x+=1;
}
# close the connection
odbc_close($connection);
?>
« Last Edit: February 25, 2016, 06:29:17 PM by MyBrainIsFull »

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11250
    • View Profile
Re: PH MS Sql connection error
« Reply #1 on: February 25, 2016, 02:00:18 AM »
alas, I know nothing about PHP so I'm not the one to ask, but maybe someone else can chip in.

cheers
Bruce

osquiabro

  • Hero Member
  • *****
  • Posts: 687
    • View Profile
    • Email
Re: PH MS Sql connection error
« Reply #2 on: February 25, 2016, 04:03:52 AM »
what OS version?

MyBrainIsFull

  • Full Member
  • ***
  • Posts: 134
    • View Profile
Re: PHP MS Sql connection error
« Reply #3 on: February 25, 2016, 06:27:00 PM »
thanks for the reply - bit of a mixture
ms sql is on server 2003
iis - I have 2 pcs that I have been trying, one is server 2008, and one is Win7

I cant see that the sql machine matters, its just a transaction to port 1433
Both Server 2012 and Win 7 box is running IIS 7 and php 5.4

I am running php 5.4 as I had endless troubles loading php 7 and gave up, started over again with 5.4

osquiabro

  • Hero Member
  • *****
  • Posts: 687
    • View Profile
    • Email
Re: PHP MS Sql connection error
« Reply #4 on: February 26, 2016, 02:28:16 AM »
what version of SQL Server?

i think the problem is 2003 server and sqlclient recently i have a problem with server 2003 and c10 and NT, after move to server 2008 all work perfect.

try to install the correct sqlclient for sql version and force yours app to use driver in clarion is DRIVER={SQL Server Native Client 11.0}  don't how in php

MyBrainIsFull

  • Full Member
  • ***
  • Posts: 134
    • View Profile
Re: PHP MS Sql connection error
« Reply #5 on: February 28, 2016, 12:47:02 AM »
I now have Server 2008 running and it looks like the drivers are working as I no longer get that error, I have moved on to this error

Security Alert! The PHP CGI cannot be accessed directly.
This PHP CGI binary was compiled with force-cgi-redirect enabled. This means that a page will only be served up if the REDIRECT_STATUS CGI variable is set, e.g. via an Apache Action directive.

So I will try to understand this tomorrow
either to go back to Capesoft's 5.29 PHP in their example, and try to find drivers to suit 5.2. Perhaps it was compiled to allow direct access from a Net Talk Server
or
Find a way for NT to set this, as Google suggests setting the PHP.ini to allow direct access (but it didnt work for me)
cgi.redirect_status_env ='yes'

Thanks again for you suggestions

MyBrainIsFull

  • Full Member
  • ***
  • Posts: 134
    • View Profile
Re: PHP MS Sql connection error
« Reply #6 on: March 02, 2016, 05:20:47 AM »
To osquiabro
Hi, thanks for your hints regarding PHP
I am still not getting Net Talk Server to send via php to a database and get a result.

Can you tell me please if you can do a SELECT and get a result set back via PHP ?

Would you mind sending me your PHP.INI    as I think that this is where I am having trouble with some setting

Also - did you have to move the php-cgi.exe to another folder (the web folder) to avoid triggering the PHP redirection security alert?

Thanks for any help you can pass me.

osquiabro

  • Hero Member
  • *****
  • Posts: 687
    • View Profile
    • Email
Re: PHP MS Sql connection error
« Reply #7 on: March 03, 2016, 04:07:05 AM »
hi, my hint is about sql server not php, i'm no expert in php, your primary problem is sql and no matter language is a same problem, so i think that san google is your best friend for your problem. ;D ;D ;D