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

Search paramaters SQLSRV_QUERY for WHERE IN syntax

$
0
0

I wonder if there is a way to pass some values into the parameters option on the sqlsrv_queryfunction. I tried a few things but could not get it to work.

This query is what I want to be executed:

SELECT id, name, etc
FROM sqlTable
WHERE id IN ('1','2','100','314')

I want to pass the WHERE IN values using the params option, like this:

$q ="SELECT id FROM sqlTable WHERE id IN ?";
$p = array(array('1','2','100','314'));
sqlsrv_query($connection, $q, $p);

Right now I'm passing the values directly into the query string, but for obvious security reasons I want to pass them as parameters into the function. Anyone any idea on how to achieve this?


Can not connect to sql server express 2012

$
0
0

Dear all.

I've installed wamp on my first PC (WINDOWS 10). I'm trying to connect my php script (since PC10) to a database on an another PC (windows 8.1). I 'm getting always the same message :

PDOException: SQLSTATE[IMSSP]: This extension requires the Microsoft SQL Server 2012 Native Client ODBC Driver to communicate with SQL Server. Access the following URL to download the Microsoft SQL Server 2012 Native Client ODBC driver for x86: http://go.microsoft.com/fwlink/?LinkId=163712

I' add in my php.in (on W10) the following lines :

  extension=php_sqlsrv_55_ts.dll
  extension=php_sqlsrv_55_nts.dll
  extension=php_pdo_sqlsrv_55_ts.dll
  extension=php_pdo_sqlsrv_55_nts.dll

and i putted the files in the php/ext directory

still got the same error message.

Could someone help?

Thank you

Getting scalar results from SQL Server Stored Procedure using PHP and sqlsrv functions

$
0
0

I have created a Stored Procedure in MS SQL 2014 which is given a username and password and returns 0: Success; 1: Username not found; or 2: Password doesn't match.

CREATE PROCEDURE authConfirmUserPass
	@username varchar(30),
	@password varchar(32),
	@resultValue int OUTPUT
AS
BEGIN
	SET NOCOUNT ON;
	-- Much processing left out
	SET @resultValue = 1
	SELECT @resultValue
END
GO

When I test this in SQL Server Management Studio, it seems to work fine

DECLARE	@resultValue int
DECLARE @password varchar(32)
EXEC [dbo].[authConfirmUserPass] N'badUserName', N'badPassword', @resultValue OUTPUT
SELECT	'Return Value' = @resultValue
GO

However, when I try to get the return value inside of PHP, the value of my output variable never seems to change:

$resultValue = -10;
$qry = "{call authConfirmUserPass( ?, ?)}";
$params = array(
	array($username, SQLSRV_PHPTYPE_STRING, SQLSRV_PARAM_IN),
	array($password, SQLSRV_PHPTYPE_STRING, SQLSRV_PARAM_IN),
	array($resultValue, SQLSRV_PHPTYPE_INT, SQLSRV_PARAM_OUT)
	);
$stmt = sqlsrv_query($this->connection, $qry, $params);
echo "<p>Result is: $resultValue</p>";
sqlsrv_next_result($stmt);
echo "<p>Next Result is: $resultValue</p>";

Calling the stored procedure does not seem to ever change the value of $resultValue. I always get -10.

Any ideas what I am doing wrong? I have spent hours searching and reading for answers online, but to no avail.



ODBC Driver Download Failed

connect to localhost instance using PDO

$
0
0

Hi,

I am just starting with SQL Server PDO drivers and I want to know how can I set the sqlsrv:server if I am going to use my localhost instance?

My localhost instance name is JASSIM-RAHMA

Thanks,

Jassim


Problem Querying using PDO

$
0
0

Hi,

I am trying to use PDO like this simple code:

<?php
	$mysql_host			=	"(local)\JASSIM-RAHMA";
	$mysql_database 	=	array("Database"=>"food");

	$mysql_connection	= sqlsrv_connect($mysql_host, $mysql_database);

	$sql_stmt			= "SELECT * FROM  groups";

	$mysql_query		= sqlsrv_query($mysql_connection, $sql_stmt);

	while($row = sqlsrv_fetch_array($mysql_query, SQLSRV_FETCH_ASSOC))
	{
		echo $row['group_id'].", ".$row['group_name']."<br />";
	}
?>

but I am getting:

Warning: sqlsrv_query() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\food\temp.php on line 9

Warning: sqlsrv_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\food\temp.php on line 11

Kindly help..

Thanks,

Jassim

php_mssql.dll not loading in PHP.ini

$
0
0

I am running PHP 5.6.21 under IIS on Windows Server 2012R2. PHP is working great.

I need PHP to connect to a Microsoft SQL database, so I have this line uncommented in php.ini: extension=php_mssql.dll

Yes, I have that file in the ext folder, and the correct folder is listed for extensions in the php.ini file.

I also have SQL Native client installed, the ODBC drivers, and the PHP SQL drivers.

When I go to connect to a SQL database, I get: Fatal error: Call to undefined function mssql_connect() in....

This EXACT code is working on an older 2003 server. 

If I look at the phpinfo on the new server, this is in the "configure command" area:

cscript /nologo configure.js "--enable-snapshot-build" "--enable-debug-pack" "--disable-zts" "--disable-isapi" "--disable-nsapi" "--without-mssql""--without-pdo-mssql" "--without-pi3web" "--with-pdo-oci=c:\php-sdk\oracle\x86\instantclient_12_1\sdk,shared" "--with-oci8-12c=c:\php-sdk\oracle\x86\instantclient_12_1\sdk,shared" "--with-enchant=shared" "--enable-object-out-dir=../obj/""--enable-com-dotnet=shared" "--with-mcrypt=static" "--without-analyzer" "--with-pgo"

That looks strange - it has "without-mssql" listed there...is this what is preventing mssql from working? Since I have the extension loading in the php.ini file, I don't know where else to look...

Any help GREATLY appreciated - Thanks!

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.



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? 


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

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.

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?

Bulk Copy?

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?

0 rows being returned from SELECT query

$
0
0

I am trying to run a SELECT query to validate attempted logins to a website. I am running the following code. My problem is that

either the query is returning 0 rows or them number of rows is not being captured. I have successfully executed the query in SSMS. I have verified it is being executed in my code by a if($stmt). I know the userid and password I am entering are valid.

Page that captures the userid and password:

?php
include('login_process.php'); // Includes Login Script

if(isset($_SESSION['login_user'])){
header("location: profile.php");
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Login Form in PHP with Session</title>
<link href="style.css" rel="stylesheet" type="text/css">
</head>
<body style="background-color:blue">

<div id="main">
<h1>PHP Login Session Example</h1>
<div id="login">
<h2>Login Form</h2>
<form action="" method="post">
<label>UserName :</label>
<input id="name" name="username" placeholder="username" type="text">
<label>Password :</label>
<input id="password" name="password" placeholder="**********" type="password">
<input name="submit" type="submit" value=" Login ">
<span><?php echo $error; ?></span>
</form>
</div>
</div>
</body>
</html>

Page that processes the SELECT query:

<?php

  $error=''; // Variable To Store Error Message
  if (isset($_POST['submit'])) {
  if (empty($_POST['username']) || empty($_POST['password'])) {
  $error = "Username or Password is invalid";
  }
   else
  {
   // Define $username and $password
   $username=$_POST['username'];
   $password=$_POST['password'];

   // Establishing Connection with Server
   $serverName = ("JOHN-PC\SQLEXPRESS");
   $connectionInfo = array( "Database" => "kc3061users");
   $conn = sqlsrv_connect($serverName, $connectionInfo);


   // SQL query to fetch information of registerd users and finds user match.
   $tsql = "SELECT userid, password FROM kc3061ligin where userid = '$userid' AND password = '$password'";

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

   $row_count = sqlsrv_num_rows($stmt);
   if ($row_count === true){
   echo "row count is ";
   echo $row_count;
   header("location: ../secure_page.html");
   }
   else {

   $error = "Username or Password is invalid";
  }
  sqlsrv_close($conn); // Closing Connection
  }
  }
?>


John Scholl


Installing MS SQL PHP drivers under Windows 2008 Server

$
0
0

Hi All,

We are trying to setup MS SQL Server access from PHP 5.4 under Apache 2.2. The host is a Windows Server 2008 SP2 Enterprise. We downloaded the drivers from http://www.microsoft.com/en-us/download/details.aspx?id=20098 (file SQLSRV30.EXE).

When we run the installer, no matter what target folder we select, we get this error message:

"That folder is invalid. Please make sure the folder exists and is writable"

Can anybody provide any hint on this? Or at least point us to a compressed file to extract the right files from. Thank you very much in advance.

Edo.

How to execute a stored procedure when using 1 param_in. The SP should return 3 values

$
0
0

Hi,

I have a stored procedure that requires @Date DATETIME

and will return a name (string) with a payout (decimal) and turnover (decimal).

There will be multiple names with decimal values returned.

I can connect to my DB fine but I am having difficulty on the connecting with the stored procedure. 

like so:

/* Connextion to SQL Server */
$server = 'tcp:address';

$credentials = array
(
  'UID'       => 'value',
  'PWD'       => 'value',
  'Database'  => 'value',
  'ReturnDatesAsStrings' =>1

);

$connection = sqlsrv_connect( $server, $credentials );
if( $connection === false )
{
        echo ("failed to connect");
        die( '<pre class="error">' . print_r( sqlsrv_errors(), true ) . '</pre>' );
}

But the parameter part I'm not sure about:

// Define parameter array
$tsql_callSP = " { call SPGetDetails( ?, ?, ?, ? ) } ";
$date = date('d-m-Y');

$params = array(
                  array( $date, SQLSRV_PARAM_IN ),
                  array( $track, SQLSRV_PARAM_OUT ) ,
                  array( $payout, SQLSRV_PARAM_OUT) ,
                  array( $turnover, SQLSRV_PARAM_OUT) ) ;

/* Get sql data */

$stmt = sqlsrv_query( $connection, $tsql_callSP, $params );
if( $stmt === false )
{
        echo ("failed to call  stored proc " );
        die( '<pre class="error">' . print_r( sqlsrv_errors(), true ) . '</pre>' );
}

// Display tracks
$nextTrack = sqlsrv_next_result ( $spConnection ) ;
$row = sqlsrv_fetch_array ( $spConnection );

sqlsrv_free_stmt( $connectoin );
sqlsrv_close ( $connection );

I just keep getting this error:

 [0] => IMSSP
            [SQLSTATE] => IMSSP
            [1] => -61
            [code] => -61

can someone please show me an example of how to return 3 parameters from a stored procedure by providing a date parameter?




CuriousCoder

Problem retrieving varchar('max') as output parameter from procedure

$
0
0

Hi,

I'm having the String data truncation problem, similar to this Thread: http://social.msdn.microsoft.com/Forums/en/sqldriverforphp/thread/780d21df-7342-4cf2-ab1b-a4fd0aac8657

In this thread, the problem was solved initiliazing the variable using a large string, this is not acceptable. Some people said that this is related to a BUG, I`ve tried to update the drivers to the latest release, but no luck. The only way to solve the problem was to initialize the php string to a large value.

Thanks very much,

Pedro Almeida

Problem with entering Polish characters in PHP

$
0
0

Good evening,

When I try to enter Polish characters (like ę, ą, ó and so on) into SQL Server via PHP, I get "strange" characters insterted instead of correct ones. Column is NVARCHAR and collation is POLISH_CI_AS and both html (form) and php file are saved in UTF-8. Creating a statement INSERT INTO TableName VALUES (N'$value'); does not help.

Need help setting up Drupal 7 with SQL Sever 2008

$
0
0

Hello,

I'm trying to learn Drupal 7.0 and setting up with SQL Server 2008. PHP is already installed and ready to go, and so is SQL Server. I already have a couple of database created and test with php with a sample site, and it works perfect. The SQL is configured to enable Named Pipe and TCP/IP, and mixed mode authentication. The authentication for NT Authority\iusr is enable and set to login as dbowner of the drupal database. But when I try to install Drupal, everything passes except for the database support. It continues to display error message..

               "Your web server does not appear to support any common PDO database extensions. Check with your hosting provider to see if they support PDO (PHP Data bjects) and offer any databases that Drupal supports."

 I've tried everything that was listed in Drupal manual. I also did a lot of google searching but couldn't find possible solution. I'm using PHP 5.3 vc8 x86 nts. Can anybody please help me set it up?

Thank you.



Viewing all 163 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>