Quantcast
Channel: Microsoft Drivers for PHP for SQL Server forum
Viewing all 391 articles
Browse latest View live

Result Differ PHP 5.6 SQL Server 2014 and SQLSRV Driver Version 3.2

$
0
0

I've spent days on this with no luck. I've read this article several times through. SQL SRV Driver White Pages. Searching with Google yielded no results that worked. Any Insight would be appreciated. 

My setup, I am running XAMPP with Microsoft's SQLSRV 3.2 driver and  SQL Server 2014 developer edition on a Windows 7 machine.

If I make this query in Microsoft's Management Studio...

USE msdb
SELECT TABLE_NAME, TABLE_TYPE FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE='BASE TABLE'

I get 143 rows returned.

If I make the same query in PHP with this code...

<?php

$newConnectionInfo = array();
$newConnectionInfo['Database'] = "msdb";
$newConnectionInfo['UID'] = "";
$newConnectionInfo['PWD'] = "";
$newConnection = SQLSRV_CONNECT("127.0.0.1", $newConnectionInfo);

if ($newConnection){
	echo "<p>Connection Established.</p>";
	$params = array();
	$tsql = "SELECT TABLE_NAME, TABLE_TYPE FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE='BASE TABLE'";
	$options = array("scrollable" => SQLSRV_CURSOR_KEYSET);
	$getNames = SQLSRV_QUERY($newConnection, $tsql, $params, $options);
	if ($getNames){
		echo "<p>I got something here.</p>";
		var_dump($getNames);
		if (SQLSRV_HAS_ROWS($getNames)){
			$rowCount = SQLSRV_NUM_ROWS($getNames);
			var_dump($rowCount);
			while ($row = SQLSRV_FETCH_ARRAY($getNames, SQLSRV_FETCH_ASSOC)){
				echo "<p>There is more to be had!</p>";
				//var_dump($row);
			}
		}
	} else {
		echo "<p>Falure</p>";
		die (print_r(SQLSRV_ERRORS(), true));
	}

} else {
	echo "<p>Falure</p>";
	die(print_r(SQLSRV_ERRORS(), true));
}

?>

then I only get back 9 rows.

If you see what my mistake is please let me know.



Driver 3.2 immpossible install on Win2012Server

$
0
0

Last week I started installation php with mssql support on Win Server 2012 R2.
All versions 3.xx of Microsoft Driver for PHP for SQL Server need Microsoft ODBC Driver 11 for SQL Server, but this one can't install on WinServ2012, only Microsoft ODBC Driver 13.

https://www.microsoft.com/en-us/download/details.aspx?id=20098
Here we can read:
Versions 3.2 and 3.1 require Microsoft ODBC Driver 11 (or higher) for SQL Server.

Its not true, allways is this error
SQLSTATE: IMSSP
code: -49
message: This extension requires the Microsoft ODBC Driver 11 for SQL Server.

Is any chance to recompile/configure driver for work with ODBC driver 13?


sqlsrv very slow over network

$
0
0

I'm using sqlsrv (php_pdo_sqlsrv_55_ts.dll and php_sqlsrv_55_ts.dll) in PHP (5.5.12, CLI version on Windows 8.1) to connect to a SQL Server 2012 over a VPN tunnel. But the transfer rate for large result sets is very slow.

Testing SSMS on the same PC over the same VPN tunnel for this query (query is just for testing purposes, I also tried other queries with large data sets and all showed the same performance issues):

    SELECT *
    FROM [Data].[dbo].[Logins]
    WHERE date >= '2014-01-27 00:00:00.000' AND date < '2014-01-29 00:00:00.000'

returns about 100,000 rows in 4 seconds. Checking the transfer rate on my firewall/VPN shows 2,500 KB/s (on a 100mbit network) while the query is running.

Using PHP:

    sqlsrv_configure('ClientBufferMaxKBSize', 1024*1024);
    $dbconnect = "SERVER\\HERE";
    $dbconinfo = array("UID" => "user", "PWD" => "pass", "Database" => "Data")
    $conn = sqlsrv_connect( $dbconnect, $dbconinfo);
    $sql = "
    SELECT *
    FROM [dbo].[Logins]
    WHERE date >= '2014-01-27 00:00:00.000' AND date < '2014-01-29 00:00:00.000'
    ";

    $options = array();
    $options["Scrollable"] = SQLSRV_CURSOR_CLIENT_BUFFERED;
    $options["QueryTimeout"] = 30000;      

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

runs 40 seconds and the firewall/VPN shows less than 150 KB/s while the query is running. Task-Manager shows around 5% CPU load for the script.

I used SQLSRV_CURSOR_CLIENT_BUFFERED just for testing, because it reads the result in its own buffer without any further PHP code. Fetching each set of data without buffering is just a little bit slower (around 45 seconds).

I also tried a PDO version which lead to the same result.

ConnectionPooling 0 or 1 didn't make any difference either.

Changing server name to DNS vs. IP adress also made no difference.

LogSubsystems -1 and LogSeverity -1 did not show any issues or anything helpful at all.

I even used Wireshark to watch the network traffic but couldn't find any big differences between PHP and SSMS versions. But I don't know too much about networking layers.

So the CPU load is low, there is no HDD use at all, the network transfer rate is extremely slow and the SQL server would be capable to deliver the results very much faster. And it actually is a lot faster with SSMS on the same PC and network connection. Why is sqlsrv so very slow?

Any ideas what might be the issue or what I could try to speed up PHP/sqlsrv would be greatly appreciated.

SQL Server has a delay in response when using SQLSRV 3.2 driver

$
0
0

I have a data driven application that is written in PHP using Laravel 5.2 framework. My application reads/writes from/to Sql Server Microsoft SQL Server 2012.

Just like any typical application, my app reads/writes/updates data on every request.

I am having issues with the application where a request takes around 10 seconds to completed and sometime longer which is not acceptable. While digging and trying to monitor each request using Clockworks, I witnessed a simple query taking over 2 seconds to execute. Here is an example of a query that took over 1300ms to return 1 record

SELECT * FROM [stext] WHERE [interview_id] = '6278' and [control_id] in ('306') ORDER BY [id] ASC

Most of the times, this query runs with no problems but in this case it took long time. I was the only user using the app at that time so the servers were not busy at all and the databases are very small. The duration 1300ms includes statement preparation time, network latency and SQL execution time.

When I execute this above query using Microsoft SQL Server Management Studio directly the query runs in 0.00 seconds with no issues.

We have dug in the network and found no problems with the traffic between my web server and the data server.

I am using ConnectionPooling when connecting to the server. But I also get the same results when not using ConnectionPooling.

My application use transaction to execute all queries with in. I start transaction, execute bunch of queries then either commit or rollback.

Could there be a SQL Server setting that needs to be changed to run things faster? Is this be a SqlSrv 3.2 driver issue?

What can I do to figure out the cause of this problem?

Thanks for your help

invalid db driver

$
0
0

I have 32 bit wamp server

32 bit php 5.5.12

CodeIgniter-3.0.4

sqlsrv32,40,30,31

and what  I get is an Invalid db driver..

can anyone please tell me wjat's wrong? 


Unofficial PHP 5.5 Drivers (x86)

$
0
0

Ok, I compile for both normal and pdo drivers with Thread Safe (x86) / Non Thread Safe (x86).
I testes Non Thread Safe PDO driver with php 5.5 (x86) and it's working.
You can download files here:
http://www.hmelihkara.com/files/php_sqlsrv_55.rar
Also I change file versions to 3.0.2 to solve confusion with the old versions.
----------------------------------
Legal:
This is a project of Microsoft Corporation and as the version.h file writes, I've permission to change the source code and distribute it with giving the details that I made and giving the copy of the license here: http://www.apache.org/licenses/LICENSE-2.0
Changes:
Line 77 of php_sqlsrv.h changes from:

#if PHP_MAJOR_VERSION > 5 || PHP_MAJOR_VERSION < 5 || ( PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION < 3 ) || ( PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION > 4 )

to:

#if PHP_MAJOR_VERSION > 5 || PHP_MAJOR_VERSION < 5 || ( PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION < 4 ) || ( PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION > 5 )

Sqlstate 42000 8114 [code]

$
0
0

Hi Guys,

I'm developing a android programme with Android Studio and as webserver I use the php. I use sql server 2012 as my database.

My problem is that I have make a php for my scoring application so I can insert points etc, but it give this error: 

Array ( [0] => Array ( [0] => 42000 [SQLSTATE] => 42000 [1] => 8114 [code] => 8114 [2] => [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Error converting data type nvarchar to numeric. [message] => [Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Error converting data type nvarchar to numeric. ) )

Here is a snippet of my code:

<?php

include('scoringconnect.php');

$hurado_id = 8;//$_POST['points_hurado'];
$id = 4;//$_POST['points_tumba'];

$tvA = 'A'; //$_POST['points_subcat'];
$tvB = 'B';//$_POST['points_subcat'];
$tvC = 'C'; //$_POST['points_subcat'];
$tvI = 'I'; //$_POST['points_subcat'];
$tvJ = 'J'; //$_POST['points_subcat'];

$etA = 25; //$_POST['points_points'];
$etB = 25; //$_POST['points_points'];
$etC = 25; //$_POST['points_points'];
$etI = 25; //$_POST['points_points'];
$etJ = 25; //$_POST['points_points'];

$date = '15-08-2016'; //$_POST['points_datetime'];

$sql = "INSERT INTO dbo.[tbl_Points] (points_hurado, points_subcat, points_tumba, points_points, points_datetime) VALUES (?, ?, ?, ?, ?)";
$params = array(&$hurado_id, &$id, &$tvA, &$tvB, &$tvC, &$tvI, &$tvJ, &$etA, &$etB, &$etC, &$etI, &$etJ, &$date);
$stmt = sqlsrv_prepare( $conn, $sql, $params);
if( $stmt === false) {
    die( print_r( sqlsrv_errors(), true));
}


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

$response = array();
$response['success'] = true;

echo json_encode ($response);
?>

Could you guys help me out with this problem.

Where to get the right download file for ODBC Driver 11 for SQL Server

$
0
0

Where to get the right download file for ODBC Driver 11 for SQL Server

Winver:

Winver

phpinfo gives:


PHP Version 5.6.13

System

Windows NT <servername> 6.0 build 6001 (Windows Server 2008 Enterprise Edition Service Pack 1) i586

Build Date

Sep 3 2015 15:07:17

Compiler

MSVC11 (Visual C++ 2012)

Architecture

x86

 

 Downloaded


Both installations fail

1)

 

2)

THX!



ODBC Connection

$
0
0

Hello,

I'm currently developing a PHP-Application, that stores data in a Microsoft SQL database. I tried connecting to the database with the sqlsrv driver, but the driver showed an error-message and said, that the ODBC driver is missing. So I installed this driver and now nothing works. When I request any page on the server, my browser can't finish loading it. There is no timeout-message, it just loads forever.

When I try executing the script on the command line it works perfectly, but not via http. Can someone help me with this? What is wrong with the ODBC driver?

Perhaps you need the following information: I use PHP 5.6 and SQLSRV 3.2.

Thankyou in advance

Problem with Stored procedure

$
0
0

Please check this below code  I am using SQL ODBC Drivers 11 , database connection is woring fine., I am trying execute SQL Stored Procedure as show below. but i am getting this below error. This stored procedure executing correctely in SQL Server Management Studio. but from php applicaiton i am getting this error. 

Please give me solution for this issue

$link_id = odbc_connect('mssql', $user,$password);
if(!$link_id){      
        exit("Connection failed:" . odbc_errormsg());
}
$sql = "exec Portal_Patient_Search 'john', 'first_name', 0, 10, 'last_name', 1, 1";
$rs=odbc_prepare($link_id,$sql);
$result=odbc_execute($rs,array(" 'version'"));

while($row = odbc_fetch_array($rs)){     
print_r($row);

odbc_execute(): SQL error: [Microsoft][ODBC Driver 11 for SQL Server]Cursor type changed, SQL state 01S02 in SQLExecute

How do I convert a mssql_field_name function to equivalent sqlsrv function

$
0
0

Hi,

    I am converting the mssql functions in my application to sqlsrv functions as part of a migration activity from SQL Server 2003 to SQL Server 2008. I am not getting the expected results when I just replace mssql_field_name with its equivalent in sqlsrv i.e sqlsrv_field_metadata. I am not sure if I am using the right sqlsrv function for this. Could anyone help me here. The code which I am trying to convert looks something like this:

$result = mssql_query($query, $conn);
$rows  = mssql_num_rows($result);
$cols = mssql_num_fields($result);

if(rows>0)
{
for($i= 0;$i<$cols;++$i)
{
$colname = mssql_field_name($result,$i);
echo " <th>$colname</th>";
}
echo "</tr>";
}

if($rows<=0){
echo "No Results found for the specified inputs";
exit();
}else
{
    for($i = 0;$i < $rows; $i++)
   {
echo "<tr>";
for($j =0;$j < $cols; $j++)
{
$colname = mssql_field_name($result,$j);
$out = mssql_result($result,$i,"$colname");
echo "<td> $out &nbsp;</td>";
}
echo "</tr>";
    }

echo "<br>";
}


nchar problem with sqlsrv driver for php

$
0
0

Hi Guys,

i am trying to retrieve some info via SELECT WHERE from a MSSQL  Server. the BranchID in mssql is nchar(20). i can just pass LIKE '%' and if i put a simple BranchID like 0422, i got nothing back to display on web page; i installed php sqlsrv 64bits. it works if ID in mssql is INT, but not luck with nchar.

could anyone advice me, please?

$connectionInfo = array( "UID"=>$uid,                              
                         "PWD"=>$pwd,                              
                         "Database"=>$databaseName,
'ReturnDatesAsStrings'=>true,
'CharacterSet'=>'UTF-8');   

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

if ( !$conn )    
{    
     echo "Error in Connection.\n";    
     die( print_r( sqlsrv_errors(), true));    
}
else
{
$server_info = sqlsrv_server_info( $conn);
if( $server_info )
{
foreach( $server_info as $key => $value) 
{
echo $key.": ".$value."<br />";
}

else 
{
die( print_r( sqlsrv_errors(), true));
}
}    
$branch="'%'";
if (isset($_GET["Branch"])) 
{
echo $_GET["Branch"]."<br />";
//$branch=stripslashes(utf8_encode($_GET["Branch"]));
$branch=stripslashes($_GET["Branch"]);
echo $branch."<br />";
$branch=strip_tags($branch);
echo $branch."<br />";
$branch=htmlentities($branch);
$branch=htmlspecialchars($branch);
echo $branch."<br /><br />";
$branch="$branch" ;
echo $branch."<br /><br />";
}
echo "$branch<br /><br />";
if ($branch=="=''")
{
$branch="'%'";
}
echo "Before tSql: $branch<br /><br />";
$tsql = "SELECT [Location_ID]
      ,[Name]
  FROM [dbo].[Locations]
  WHERE [Location_ID] = ?";       
$param=array($branch,null,SQLSRV_PHPTYPE_STRING (SQLSRV_ENC_BINARY),SQLSRV_SQLTYPE_NCHAR(20));
print_r( $param );
echo "<br />$tsql<br /><br />";  
    
$stmt = sqlsrv_query( $conn, $tsql,$param );    
    
if( !$stmt )
{
echo "Error in SELECT execution.\n";    
die( print_r( sqlsrv_errors(), true));
}

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

$nof=sqlsrv_num_fields( $stmt );
echo "no of fields: $nor";
//HTML Table
echo "<table><tr>";

$row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC);
foreach (array_keys($row) as $f)
{
echo "<td>$f</td>";
}

do
{
echo "<tr>";
foreach ($row as $f)
{
echo "<td>$f</td>";
}
echo "</tr>\n";
}
while ( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC));

Can't access SQL Server using PHP

$
0
0

Good Evening,

I installed SQL Server 2016 Enterprise on Windows Server 2012 R2 and PHP using Microsoft WPI. I added the following lines in the php.ini file:

extension=php_sqlsrv_7_ts_x86.dll
extension=php_sqlsrv_7_ts_x64.dll

However, when I check phpinfo(), I can't  see sqlsrv info box.

confugure PHP for Sql Server2008

$
0
0

In my computer, I have installed SQL Server 2008. I want to confugure PHP for SQL Server 2008 that I could develop a interface for Android Application developing.

Please share me a detail steps, thank you very much.

Error to connect MSSQL database through PHP

$
0
0

I can open the .php file in window server 2016 TP5 and PHP 7.0.9. After I upgrade my system to Window Server 2016 and PHP 7.1, I cannot connect to the MSSQL Server.

When I open the .php file in the browser, it displays an error message "Fatal error: Uncaught Error: Call to undefined function sqlsrv_connect() in C:\inetpub\wwwroot\count.php:6 Stack trace: #0 {main} thrown in C:\inetpub\wwwroot\count.php on line 6"

When I use back PHP 7.0.9, I get another error "Connection could not be established. 
Array ( [0] => Array ( [0] => 28000 [SQLSTATE] => 28000 [1] => 18456 [code] => 18456 [2] => [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]Login failed for user 'LIGHT\SERVER$'. [message] => [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]Login failed for user 'LIGHT\SERVER$'. ) [1] => Array ( [0] => 28000 [SQLSTATE] => 28000 [1] => 18456 [code] => 18456 [2] => [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]Login failed for user 'LIGHT\SERVER$'. [message] => [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]Login failed for user 'LIGHT\SERVER$'. ) )"

How to solve this error?


SQLSRV Files Available for PHP 7.1

$
0
0

Hi,

SQLSRV Driver file is available for PHP 7.1 Version ? or need to use SQLSRV4.0 ?

Could you please guide me?

Thanks

Bulk Copy?

[Microsoft][ODBC Driver 13 for SQL Server][SQL Server]Operand type clash: text is incompatible with datetime in PHP

$
0
0
<style type="text/css">p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco} p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco; min-height: 15.0px} span.Apple-tab-span {white-space:pre} </style>

I followed the step of: 

file:///Users/oscar/Desktop/Linux_4.0_Install_Instructions.pdf
with pdo, but obtain always this errors if I use the bindValue:

19/01/2017 09:34:00Logger::ERRORError:

Array

(

    [0] => 42000

    [1] => 402

    [2] => [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]The data types nvarchar and text are incompatible in the equal to operator. (SQLExecute[402] at /home/webuser/src/php-7.1.0/ext/pdo_odbc/odbc_stmt.c:260)

    [3] => 42000

)

19/01/2017 09:35:18Logger::ERRORError:

Array

(

    [0] => 22018

    [1] => 206

    [2] => [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]Operand type clash: text is incompatible with datetime (SQLExecute[206] at /home/webuser/src/php-7.1.0/ext/pdo_odbc/odbc_stmt.c:260)

    [3] => 22018

)

if I replace the "?" with cast(? as varchar) then all it's ok. The good thing is that if I use simplex query like "select * from table where id = ? " then work fine, if I use query more complex then obtain the error.

Centos 7

Apache 2.4

php 7

thanks 

PHP Startup: Unable to load dynamic library 'php_pdo_sqlsrv_7_nts_x64.dll' - La procédure spécifiée est introuvable.

$
0
0

Hi all,

I installed :

  • PHP 7.1 64 bits NTS on Windows 10 x64
  • MSSQL Server 2016 Express x64
  • Microsoft ODBC Driver 13.1
  • Microsoft PHP Driver 4.0 (php_pdo_sqlsrv_7_nts_x64.dll)

I added extension into php.ini.

After a full restart of the computer, I get the error message indicated into the post title.

PHP Startup: Unable to load dynamic library 'php_pdo_sqlsrv_7_nts_x64.dll' - La procédure spécifiée est introuvable.

Could you help ? What did I forget ?

Thanks for help

Apache vs IIS - Can the PHP / SQL Drivers be used with Apache + PHP + SQL instead of IIS + PHP + SQL Server?

$
0
0

Trying to get an Apache + PHP + SQL server upgraded to newer software.  Having problems.  Wondering if PHP SQL Server extensions are compatible with Apache.

I have previously used a configuration with Apache2.2 + PHP5 + SQL Server 2008 R2 for years which has worked wonderfully.   I'm now trying to upgrade to:

Apache 2.4

PHP 7.0  (ThreadSafe)

SQL 2008 R2 and eventually SQL 2014

Windows 7 SP1, 64 Bit

I got Apache and PHP connected and working (before PHP SQL drivers).  I've then tried to load the PHP SQL server extensions (x64 TS versions).  Also added version 11 odbc driver.   Tried to add the version 11 SQL Native Client but SNAC wouldn't install.  

After loading the PHP SQL server extensions in my Ext folder:

php_sqlsrv_7_ts_x64

php_pdo_sqlsrv_7_ts_x64

Neither sqlsrv or PDO extensions will load when PHP loads.  They do not show up when I run the PHPInfo() command to view the PHP setup.  I've done all the basic stuff (I hope) like restarting Apache, verifying the X64 vs X86 versions, verified my spelling, added the loadModule command, enabled extensions,  etc..


PHP ERROR LOG:

PHP Warning:  PHP Startup: Unable to load dynamic library 'C:\\PHP\\ext\\php_sqlsrv_7_ts_x64.dll' - The specified procedure could not be found.\r\n in Unknown on line 0

PHP Warning:  PHP Startup: Unable to load dynamic library 'C:\\PHP\\ext\\php_pdo_sqlsrv_7_ts_x64.dll' - The specified procedure could not be found.\r\n in Unknown on line 0

In any event, is it even possible to use these drivers with Apache instead of IIS?   Also, the error log is weird in that its showing double "\\" in the error log file path description.  I would not expect to see that.

I've previously had to copy that pesky NTWDBLIB.DLL into system32 on my xp web server.  Could that be the problem in X64 win7?  Also had to copy msvcr71.dll previously as well.  Don't know if they are used in X64 Win 7 OS.

Any ideas?

Viewing all 391 articles
Browse latest View live