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

WAMPSERVER 'PDOException' with message 'could not find driver'

$
0
0

Hi All,

I'm running wampserver 64 bit version with:

Apache : 2.4.4 MySQL : 5.6.12 PHP : 5.4.12 PHPMyAdmin : 4.0.4 SqlBuddy : 1.3.3 XDebug : 2.2.3

I have downloaded the Microsoft Drivers 3.0 for PHP for SQL Server.

I have put the drivers in my ext folder C:\wamp\bin\php\php5.4.12\ext

php_pdo_sqlsrv_54_ts.dll

php_sqlsrv_54_ts.dll

I have changed my php.ini file to included:

extension=php_sqlsrv_54_ts.dll
extension=php_pdo_sqlsrv_54_ts.dll

I have restarted my PC.

When I run the following php code:

<?php


$database = "master";
$conn = new PDO( "sqlsrv:server=(local) ; Database = $database", "", "");

?>
 

I still get the following error message:

Fatal error: Uncaught exception 'PDOException' with message 'could not find driver' in W:\wamp\www\sqlservertestV02.php on line 4

I have tried everything I can think of but the driver does not seem to load correctly.

Any help would be greatly appreciated.

Kind regards,

Ernst.


How can I get a YYYY-mm-dd format datetime data from sql server 2005+ with Sqlsvr Driver

$
0
0

It returns an object like

DateTime Object
(
    [date] => 2011-10-20 00:00:00
    [timezone_type] => 3
    [timezone] => Asia/Chongqing
)

for MSSQL Driver, we can set mssql.datetimeconvert   =   Off   in php.ini file

but there's no similar settings for sqlsvr ...

"Severe error translating Unicode" when calling sqlsrv_fetch_array on a query with buffered cursor and empty nvarchar result

$
0
0

Hi,

This is a problem I'm having in SQL Server 2008 R2 (on Windows Server 2008 R2 Enterprise). I'm using SQLSRV 3.0 and SQL Server 2012 Native Client. This is how you can (probably) reproduce the problem:

1. Create a table which has at least one nvarchar field. In my case, the DB collation is Arabic_CI_AS, although I don't know if it matters.

2. Insert at least one record in the table, in which the nvarchar field is assigned the empty string value (not NULL).

3. Execute a query using sqlsrv_query on the table which should return at least the nvarchar field of the above record. Specify buffered cursor when calling the query.

4. The query executes without any problem, but trying to fetch the row with empty nvarchar string using sqlsrv_fetch_array results in a fatal error which says "Severe error translating Unicode in <filename>".

Sorry if this should not have been reported here, I was not sure. Is this really a bug? Should I add it to the issue tracker?

This problem can apparently be worked around by converting empty nvarchar values to NULL or something else, by converting the nvarchar type to something else, or by using some server-side cursor type.

This extension requires the Microsoft SQL Server 2012 Native Client

$
0
0

Hi everyone

I hope you can help me with thie problem, I am about 5 days without any solution.

I am trying to make a connection between SQL Server and PHP with this aspects:

  • Windows Server 2012 Standard (64b)
  • Windows Server 2008 R2
  • Apache 2.4.4 (32b)
  • PHP 5.4.16 (32b)

I had downloaded all this DLLs from Microsft web site:

  • php_pdo_sqlsrv_53_ts.dll
  • php_pdo_sqlsrv_53_nts.dll
  • php_sqlsrv_53_ts.dll
  • php_sqlsrv_53_nts.dll
  • php_pdo_sqlsrv_54_ts.dll
  • php_pdo_sqlsrv_54_nts.dll
  • php_sqlsrv_54_ts.dll
  • php_sqlsrv_54_nts.dll
  • php_mssql.dll
  • ntwdblib.dll

I know I only need php_sqlsrv_54_ts.dll library, because I have PHP 5.4.16 (32b) version and Thread Safety is enabled.

I had copy all those to this locations:

  • C:\wamp\bin\php\php5.4.12
  • C:\wamp\bin\php\php5.4.12\ext
  • C:\Windows
  • C:\Windows\System32

Even my PHPINFO() says this:

PDO_SQLSRV is working and enabled

SQLSRV is working and enabled

Beside that I had installed all the requirements for SQL Client to work. Let me show you my installed software:

And even with all of that and aaaaaallll the formus readed I desided to ask why is this .... still getting appear in my web browser?

array(size=2)
  0 =>array(size=6)
      0 =><small>string</small> 'IMSSP'(length=5)
      'SQLSTATE' =><small>string</small> 'IMSSP'(length=5)
      1 =><small>int</small> -49
      'code' =><small>int</small> -49
      2 =><small>string</small> 'This extension requires the Microsoft SQL Server 2012 Native Client. Access the following URL to download the Microsoft SQL Server 2012 Native Client ODBC driver for x86: http://go.microsoft.com/fwlink/?LinkId=163712'(length=216)
      'message' =><small>string</small> 'This extension requires the Microsoft SQL Server 2012 Native Client. Access the following URL to download the Microsoft SQL Server 2012 Native Client ODBC driver for x86: http://go.microsoft.com/fwlink/?LinkId=163712'(length=216)
  1 =>array(size=6)
      0 =><small>string</small> 'IM002'(length=5)
      'SQLSTATE' =><small>string</small> 'IM002'(length=5)
      1 =><small>int</small> 0
      'code' =><small>int</small> 0
      2 =><small>string</small> '[Microsoft][Administrador de controladores ODBC] No se encuentra el nombre del origen de datos y no se especific� ning�n controlador predeterminado'(length=147)
      'message' =><small>string</small> '[Microsoft][Administrador de controladores ODBC] No se encuentra el nombre del origen de datos y no se especific� ning�n controlador predeterminado'(length=147)


this is my connection string:

Please if you can tell me something I will be really gladd with you.

Thanks in advanced.

Javier.

This extension requires the Microsoft SQL Server 2012 Native Client. Access the following URL to download the Microsoft SQL Server 2012 Native Client ODBC driver for x86

$
0
0

I tried to connect from php to SQLSERVER2012 on my ISP's server:

Any Ideas?

Thanks,

Milt

<?PHP

   dl('c:\ppht\php_sqlsrv_53_ts.dll');    $hostname = "dba2012.db.2818339.hostedresource.com";
    $username=$database = "dba2012";
    $password = "Sx3edc4rfv!";
    $connectionInfo = array( "Database"=>"dba2012");     //Connecting to database
    try {
        $connect=sqlsrv_connect($hostname,$connectionInfo);
       if($connect==false) {
         echo "Could not connect.\n";
         die(print_r(sqlsrv_errors(),true));
      }
    } catch (Exception $e) { echo "e->getMessage()=$e->getMessage()"; }
?>

And got the following warning:

Could not connect.
Array (
    [0] => Array
        (
            [0] => IMSSP
            [SQLSTATE] => IMSSP
            [1] => -49
            [code] => -49
            [2] => This extension requires the Microsoft SQL Server 2012 Native Client. Access the following URL to download the Microsoft SQL Server 2012 Native Client ODBC driver for x86: http://go.microsoft.com/fwlink/?LinkId=163712
            [message] => This extension requires the Microsoft SQL Server 2012 Native Client. Access the following URL to download the Microsoft SQL Server 2012 Native Client ODBC driver for x86: http://go.microsoft.com/fwlink/?LinkId=163712
        )

    [1] => Array         (
            [0] => IM002
            [SQLSTATE] => IM002
            [1] => 0
            [code] => 0
            [2] => [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
            [message] => [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
        )
)




miltonkbenjamin

Getting Connection was time out while trying to execute query using PDO and MSSQL?

$
0
0
I am trying to get records from MSSQL database using PDO. But everytime i got connection was reset and i am not able to view any error on webpage. But when i run small query it works fine.

Restoring a File

$
0
0

Hi Folks,

I have a .db file of 2.6gb. Now I need to restore it in SQL Server 2008 R2 or 2012 RC0. Can any1 please let me know how to do this. I have already Googled but no good tips.


Chaos isn’t a pit. Chaos is a ladder. Many who try to climb it fail and never get to try again. The fall breaks them. And some are given a chance to climb, but they refuse. They cling to the realm, or the gods, or love. Illusions. Only the ladder is real. The climb is all there is.

Stored procedure returns empty result set.

$
0
0

I have PHP v5.2.8, Windows Server 2008, SQL Server 2005, SQL Driver for PHP v1.0.8204 (dll v1.0.1307).

Stored procedure looks like:

[dbo].[sp_users](@cid as bigint = NULL,@cname as varchar(200) = 'Пользователь', @include_descenders as bit = 0,@date as datetime = NULL)   
as   
 begin   
 if (@date is nullset @date = GETDATE()   
 select e.eid,u.login   
   from dbo.fn_class_objects(@cid,@cname,@include_descenders,@date) e   
        inner join e_users u on e.eid = u.eid   
 order by login   
 end  


I execute this procedure from PHP:

<?php     
$stmt = sqlsrv_query($connection"exec sp_users '1234'");     
$r=sqlsrv_fetch_array($stmt);     
var_dump($r);    
var_dump(sqlsrv_errors(SQLSRV_ERR_ALL));    
sqlsrv_free_stmt($stmt);     
?>  

 

Procedure raises no error, but result set($r) is empty and sqlsrv_error() return this message:

The active result for the query contains no fields

PHP output:

bool(false)   
array(1) {   
  [0]=>   
  array(6) {   
    [0]=>   
    string(5) "IMSSP"   
    ["SQLSTATE"]=>   
    string(5) "IMSSP"   
    [1]=>   
    int(-28)   
    ["code"]=>   
    int(-28)   
    [2]=>   
    string(51) "The active result for the query contains no fields."   
    ["message"]=>   
    string(51) "The active result for the query contains no fields."   
  }   
}   
 

 


Being executed in Managment Studio this procedure returns a row.






PDO, stored procedures, and returns

$
0
0

I'm having difficulty retrieving a return value from a stored procedure through PDO using the newest sqlsrv_pdo driver. 

alter PROCEDURE InsertTestTable @sData varchar(50), @retval INT
AS
if (@sData in (select SomeData from testtable))
 SET @retval=0
else
 SET @retval=1
 
RETURN @retval

I've tried several iterations of this code, such as setting @reval OUTPUT and not returning anything, and just returning 1 and 0.  Nothing seems to work.

Here is my php, which I've also tried several iterations of:

$sql="InsertTestTable ?"; //also tried $sql="exec InsertTestTable()", "exec InsertTestTable(?)", "exec InsertTestTable ?", etc.
$param='foo';
$retval=5;
$dbobj = $db->prepare($sql);
$dbobj->bindParam(1,$param,PDO::PARAM_STR);
$dbobj->bindParam(2,$retval,PDO::PARAM_INT|PDO::PARAM_INPUT_OUTPUT,100);
$dbobj->execute();
print $param;
print $retval;
if($retval)
   print "<P>FIND SUCCESSFUL</P>";
else
   print "<p>FIND UNSUCCESSFUL</P>";

Essentially all I want to do is have a stored procedure that will accept an input parameter, check to see if that value is in a table, and return a 1 or 0 (true/false) depending on that result.

What am I missing?

How to install Microsoft SQL Server 2012 Native Client ODBC driver for x86 on system x-64

$
0
0
Good day.

We have Windows Server 2008 R2 Enterprise X64 and SQL SERVER 2005

Also we install php5.4 VC9 x86 Non Thread Safe and sqlsrv for this version.

When we make connect to server we get error:

    Array
    (
        [0] => Array
            (
                [0] => IMSSP
                [SQLSTATE] => IMSSP
                [1] => -49
                [code] => -49
                [2] => This extension requires the Microsoft SQL Server 2012 Native Client. Access the following URL to download the Microsoft SQL Server 2012 Native Client ODBC driver for x86: http://go.microsoft.com/fwlink/?LinkId=163712
                [message] => This extension requires the Microsoft SQL Server 2012 Native Client. Access the following URL to download the Microsoft SQL Server 2012 Native Client ODBC driver for x86: http://go.microsoft.com/fwlink/?LinkId=163712
            )
    ...

As we can see need install Microsoft SQL Server 2012 Native Client ODBC driver for x86 but when we have system x-64 and when we start installer we get error that installer x86 is not suitable for my operation system(for x64).

Anybody know what we should do for close problem?

P.S.: 

**link on phpinfo - `http://194.58.88.58/test.php`** 

 **link on error `http://view-source:http://194.58.88.58/`**

Cant get php 5.4 to talk to sql...please help!

$
0
0

Hello

Ive recently bought some server space with FastHosts. They are running PHP 5.4. I can get PHP to echo back messages back to me so that is working. I have set up a MS SQL 2008 database on the hosting server.

I cant get PHP to communicate with the SQL database. 

this is my test code

 <?php
 

$serverName = "2xx.xxx.xxx.xxx";


try
{
$conn = new PDO( "sqlsrv:server=$serverName ; Database=Incentives", "TobyHodkinson", "xxx");
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
}
catch(Exception $e)

die( print_r( $e->getMessage() ) ); 
}

?>

Do i need to include a link to a driver?

Please note that my host wont let me change PHP.ini on the server.

Thankyou

Toby

Microsoft Drivers for PHP crashing

$
0
0

Hi folks,

I have a PHP application that needs to be moved to a later environment.  I am testing it with php 5.5.13 and it mostly works. However, when it tries to connect to the database - the application just hangs.

I found that the blocking line is a call to sqlsrv_connect  - the extensions for this are not enabled in PHP.

When I try and load any of the extensions I get an app-crash as soon as the site tries to load (so no code executed).

The server OS is 2012 R2 and the database is SQL Server 2014 (although its not getting far enough in the code to try and connect to SQL Server as the extensions are crashing).

Web server is IIS 8.5.

Does anyone have any ideas on how to get this to work?   just wondering if I need to compile the drivers (from codeplex) on the target platform or something.

Alternatively, if there is a different way of making a connection to SQL server on this platform, it might be easier just to use that.

Regards

Andy

sql_query not returning rows.

$
0
0

Hi Folks,

I am trying to execute a standard   'select * from x'  statement using PHP 5.4 and the PHP SQL Drivers (5.5 as 64bit) and am getting no rows returned (there should be about 20).

The code is:  $result = sql_query($db_handle, $query, null);    with $result containing nothing.

$db_handle contains a valid resource id and $query contains "select * from x'.

I have all of the logging enabled (and nothing is being output error wise (LogSubsystems=-1 and LogSeverity=-1) - also have display_errors set and nothing being output.

Running SQL Server profiler I see an audit_login followed by a query (rpc_completed).  exec sp_cursoropen @p1 output, N'select * from x', @p3, output, @p4 output, $p5 output

The following line in the profiler is 'audit logout'

No data is returned.   If I cut and paste the query into SQL server management studio I get 20 rows returned.

I have tried putting some invalid SQL in (select FROM x settings) but no error is given when the query is executed (although I do see it appear in the SQL Server profiler.

Does anyone have an idea on what might be going wrong?

Regards

Andy

Update:  I also get in the SQL Profiler

SQL:BatchStarting:  Select * from x,  

SqlBatchCompleted: Select * from x,

But no rows are returned.

Resolution: Upon logging in to the database server via a remote SQL Management Studio session using the UID/PWD off the PHP sql_connection it was determined that the user did not have read permissions on the database.  No error was being returned.    Correct permissions were assigned to the login and all is working.

PDO statements and nvarchar

$
0
0

Hi everybody,

I'm rewriting some old and unsecure code of mine, which did not make use of PDO or prepared statements and I would like some help/clarification about nvarchar parameters inside prepared statements.
For example, in my old code I had something like this:

"SELECT
  *
FROM
  CONTACTS
WHERE
  CONTACTS.NAME LIKE N'%" . $name . "%'";

Where CONTACTS.NAME is a nvarchar.
First of all, what does the N'' prefix really mean in case of PHP scripts? I mean, PHP strings are not internally stored as UNICODE (here), so, what is really going to happen when (for example) a string containing Chinese characters is passed as value for $name?
Is the N prefix needed for any kind of input or just for constant literals ?

In case the N prefix is needed how should I behave using prepared statements?
For example:

$sql = "SELECT
          *
        FROM
          CONTACTS
        WHERE
          CONTACTS.NAME LIKE :name";

$stmt = $connection->prepare($sql);
$name = "%test%";
$stmt->bindParam(":name", $name);



Do I need to insert the N'' prefix here or not? If yes where? 
I'm just trying to understand if and where we are making unnecessary conversion between data type, in order to avoid time and resource consumption.

Thanks in advance,
Carlo Pastorino


500 Internal server error while running sqlsrv_query in PHP

$
0
0

Hello everyone I am having a problem with sqlsrv_query I will be grateful to you please provide some help.

I am running a query through php:

$ls_parcel_query = "select  * from  ParcelDetail order by ExtractDate";

$result = sqlsrv_query($conn, $ls_parcel_query, array(), array("Scrollable"=>"keyset","QueryTimeout"=>300));
$no_of_rows = sqlsrv_num_rows($result);
echo "<br/>".$no_of_rows;

It gives (After 30 seconds):

500 - Internal server error.

There is a problem with the resource you are looking for, and it cannot be displayed.

I have php.ini settings like below:

max_execution_time = 90

memory_limit = 128M

While running this query in SQL SERVER 2008 R2, it successfully gives result in some times in 1 minute and sometimes in 2 minutes.




How to handle SQL connection if password Active directory always change? (Connection using Active directory via network SQL 2012 )

$
0
0

I have 3 server (Web server, database sql 2012 server and Active directory). I'm using sqlsvr version 3.0,  PHP version 5.3 ,IIS version 7 and windows server 2008.

Right now my php connection to SQL 2012 using AD id, so How to handle if password on active directory change?

SQL Driver for PHP 5.5 64bit + Windows Server 2012 IIS8

$
0
0

Hi there,

wanted to ask how the chances are for a sqlsrv driver for the new php 5.5 x64? I ask, because development

on the driver seems to be completely stopped, or am I wrong?

Thanks

SQL Server Native Client 11.0 - Login failed for user ''

$
0
0

Just installed the SQL Server Native Client 11.0 on our CentOS box, trying to get it connected to an external SQL database.

If I run the test isql command with the username and password from the command line, it's fine and it connects: isql -v bksblive myuser mypass

However, when I try to get it to use the UID and PWD values stored in the odbc.ini file to connect with just the DSN, which we used to do using the freetds driver, it seems to ignore them completely and fails saying i was trying to login with the user: '' isql -v bksblive

Here is the odbcinst.ini file:

[SQL Server Native Client 11.0]
Description=Microsoft SQL Server ODBC Driver V1.0for Linux
Driver=/opt/microsoft/sqlncli/lib64/libsqlncli-11.0.so.1790.0
Threading=1
UsageCount=1

Here is the odbc.ini file:

[bksblive]
Driver = SQL Server Native Client 11.0Database= bksb_ClientDatabase
Server = myip,myport
UID = myuser
PWD = mypass
Trace =On
TraceFile =/var/log/odbc.log

I read somewhere in my googling that this native client ignores the UID and PWD if they are in plain text.. but it didn't say how to get around that issue.

Can anyone help?

Thanks.

MS SQL connectivity with PHP

$
0
0
Hi dears I hope that you will be fine I want help about MS SQL database connectivity with PHP. I am working on my assignment and I am using neatbeans as PHP editor and XAMM server the probelm is that the connection is established with only sample database"AdventureWorksDW2012" other than this database (either it is created by me or it is sample database like "AdventureWorks2012") it returns error. Error is


there is an errorArray ( [0] => Array ( [0] => 28000 [SQLSTATE] => 28000 [1] => 18456 [code] => 18456 [2] => [Microsoft][SQL Server Native Client 11.0][SQL Server]Login failed for user 'NT AUTHORITY\SYSTEM'. [message] => [Microsoft][SQL Server Native Client 11.0][SQL Server]Login failed for user 'NT AUTHORITY\SYSTEM'. ) [1] => Array ( [0] => 42000 [SQLSTATE] => 42000 [1] => 4060 [code] => 4060 [2] => [Microsoft][SQL Server Native Client 11.0][SQL Server]Cannot open database"Mobiquiz" requested by the login. The login failed. [message] => [Microsoft][SQL Server Native Client 11.0][SQL Server]Cannot open database "Mobiquiz" requested by the login. The login failed. ) [2] => Array ( [0] => 28000 [SQLSTATE] => 28000 [1] => 18456 [code] => 18456 [2] => [Microsoft][SQL Server Native Client 11.0][SQL Server]Login failed for user 'NT AUTHORITY\SYSTEM'. [message] => [Microsoft][SQL Server Native Client 11.0][SQL Server]Login failed for user 'NT AUTHORITY\SYSTEM'. ) [3] => Array ( [0] => 42000 [SQLSTATE] => 42000 [1] => 4060 [code] => 4060 [2] => [Microsoft][SQL Server Native Client 11.0][SQL Server]Cannot open database "Mobiquiz" requested by the login. The login failed. [message] => [Microsoft][SQL Server Native Client 11.0][SQL Server]Cannot open database "Mobiquiz" requested by the login. The login failed. ) )



I can't understand that why this error is returned. I have installed drivers for PHP.If anybody knows about it please help me about this issue

W2k12 + IIS + PHP 5.6 + SQL Express 2012 >>> error to connect PHP to DB

$
0
0

Hi,

this is a fresh install of Windows Server 2012 where I used 'MS Web Plataform Installer' to install PHP (after I installed mannualy the 'Visual C++ Redistributable for Visual Studio 2012 Update 4'). The PHP is working and then I installed the MS SQL 2012 Express, I already set up the MSSQL TCP properties to connect by IP address since I´m able to connect using .ASP files.

<%
        Set cn = Server.CreateObject("ADODB.Connection")
        cn.Open "Provider=SQLOLEDB;Server=192.168.100.22;Database=ruedb;UID=sa;PWD=sql20015;"
        cn.CommandTimeout = 900
        cn.Close
        Response.write("Connected Successfully")
%>


I already download the 'Microsoft Drivers 3.0 for PHP for SQL Server' from 'http://www.microsoft.com/en-us/download/details.aspx?id=20098' and then extracted to 'C:\Program Files (x86)\PHP\v5.6\ext'. Now I need to set up the PHP to stablish communication with that DB.

<?php
	$link = mssql_connect('192.168.100.22', 'sa', 'sql20015');
	if(!$link) {
		echo'Could not connect';
		die('Could not connect: ' . mssql_error());
	}
	echo'Successful connection';
	mssql_close($link);
?>


but shows the following msg:

Fatal error: Call to undefined function mssql_connect() in C:\inetpub\wwwroot\rue103\testedb.php on line 2

The installer of the app show the following:

SQL Server (SQLSRV):  NOT AVAILABLE (See http://www.php.net/manual/en/ref.pdo-sqlsrv.php)

My current PHP.INI call this extensions:

[ExtensionList]
extension=php_curl.dll
extension=php_exif.dll
extension=php_gd2.dll
extension=php_gettext.dll
extension=php_imap.dll
extension=php_mbstring.dll
extension=php_mysql.dll
extension=php_mysqli.dll
extension=php_openssl.dll
extension=php_pdo_mysql.dll
extension=php_pdo_sqlite.dll
extension=php_pdo_sqlsrv_54_nts.dll
extension=php_soap.dll
extension=php_sqlsrv_54_nts.dll
extension=php_tidy.dll
extension=php_xmlrpc.dll

>>> Should I install anything else?

>>> Does anyone have idea about the development enviroment (Visual Studio vXYZ) of these .DLLs?
Viewing all 163 articles
Browse latest View live


Latest Images

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