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

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.


pymssql - SQL Server 2008 R2 Connection Error - URGENT HELP REQUIRED

$
0
0

Trying to connect SQL Server 2008 R2 through python script. I am able to connect using the adodbapi library, but When I am using pymssql library getting the following error. This is happening only in one SQL server, other SQL Server with same configuration are working fine. 

(<class 'pymssql.OperationalError'>, OperationalError((18456, "Login failed for user 'XXXXXX'.DB-Lib error message 20018, severity 14:\nGeneral SQL Server error: Check messages from the SQL Server\nDB-Lib error message 20002, severity 9:\nAdaptive Server connection failed (XXXXXXXX.XXXXX.com:3XX3)\n"),), <traceback object at 0x000000000DDD0508>):(18456, "Login failed for user 'XXXXXX'.DB-Lib error message 20018, severity 14:\nGeneral SQL Server error: Check messages from the SQL Server\nDB-Lib error message 20002, severity 9:\nAdaptive Server connection failed (XXXXXXXX.XXXXX.com:3XX3)\n")

"Invalid cursor state" when a prepared statement is re-used after an empty transaction has been committed

$
0
0

Hi,

I tracked down an issue. An unexpected exception ("Invalid cursor state") occurs with php 7.2.6/linux when a prepared statement is re-used after an empty transaction has been committed.

For reproduction code see below. This could be avoided by either not starting the transaction at all or performing a dummy operation inside the transaction. However, this is not such an easy change as it may seem in a big application where such situations might be difficult to discover (e.g. let's say a transaction is started outside a loop that is regularly iterating n > 0 times but sometimes, when n = 0, the transaction stays empty and the commit will then trigger the "Invalid cursor state" exception).

Best regards
Lars

<?php
/*
 * php version: [7.2.6]
 * sapi name: [apache2handler]
 * sqlsrv_client_info:
 *      [DriverName] => libmsodbcsql-13.1.so.9.0
 *      [DriverODBCVer] => 03.52
 *      [DriverVer] => 13.01.0009
 *      [ExtensionVer] => 5.2.0
 */
try {
    $db_conn = get_db_conn_sqlsrv();

    echo '<br>php version: [' . phpversion() . ']';
    echo '<br>sapi name: [' . php_sapi_name() . ']';
    echo '<br>sqlsrv_client_info: [' . print_r(sqlsrv_client_info($db_conn), true) . ']';

    // prepare & execute an arbitrary statement
    $query = <<<SQL
        SELECT 1 AS test
SQL;
    $ps = sqlsrv_prepare($db_conn, $query, array(), array('Scrollable' => SQLSRV_CURSOR_FORWARD));
    if (!$ps) {
        throw new Exception(print_r(sqlsrv_errors(), true));
    }
    if (!sqlsrv_execute($ps)) {
        throw new Exception(print_r(sqlsrv_errors(), true));
    }
    $result = sqlsrv_fetch_array($ps);
    var_dump($result);

    // begin & commit an empty transaction
    if (!sqlsrv_begin_transaction($db_conn)) {
        throw new Exception(print_r(sqlsrv_errors(), true));
    }
    if (!sqlsrv_commit($db_conn)) {
        throw new Exception(print_r(sqlsrv_errors(), true));
    }

    // re-execute the prepared statement -> error: SQLSTATE 24000, "[Microsoft][ODBC Driver 13 for SQL Server]Invalid cursor state"
    if (!sqlsrv_execute($ps)) {
        throw new Exception(print_r(sqlsrv_errors(), true));
    }
    $result = sqlsrv_fetch_array($ps);
    var_dump($result);
} catch (Exception $e) {
    var_dump($e);
}

function get_db_conn_sqlsrv()
{
    $host = "127.0.0.1\SQLExpress,1433";
    $conn_info = array(
        'Database'                 => '[to_be_replaced]',
        'MultipleActiveResultSets' => true,
        'CharacterSet'             => 'UTF-8',
        'UID'                      => '[to_be_replaced]',
        'PWD'                      => '[to_be_replaced]'
    );

    sqlsrv_configure('WarningsReturnAsErrors', 0);
    $conn = sqlsrv_connect($host, $conn_info);
    if (!$conn) {
        throw new Exception(print_r(sqlsrv_errors(), true));
    }

    return $conn;
}

How to decide Target size while shrinking DBCC shinkfile

$
0
0

Currently , On our server there is only 2 GB free space is available out of 2 TB

So I decide to shrink out largest size DB having size 1.8 TB

I tried below command but its not making free space

Could you advise how to decide target size for

-- Make DB in simple recovery mode --

DBCC SHRINKFILE ( file name>, <target size> )

Below are my DB size as per script

DB Initial size - 933 GB

 

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.



How do I import Subscript and Superscript from an excel file to mySQL Database?

$
0
0

We have a lot of chemistry MCQs in an excel file with lot of chemistry formulas and equations. When we tried to import these MCQs into mySQL based database all subscripts used in formulas lost and taken as normal character e.g, H2SO4, CO2, CH3 etc and makes our formulas and elements name nonsense. Using PHP n mySQL

Is there any solution by which mySQL can import subscript and superscript as it is from excel? Or Is there any solution so we can force excel to consider subscript and superscript as inserted symbols because mySQL can pick symbols as it is?

need to continue to use "mssql" functions

$
0
0
i have Ubuntu 16.04, PHP7.0, FreeTDS which connects to remote msSQL database server via command line, remote db is: Microsoft SQL Server 2008 R2 (RTM) - 10.50.1600.1 (X64). but i need to port in old code with mssql_connect, mssql_query, and mssql_fetch_array. how can i configure my server to also run code that uses the mssql functions?

integration of mysql server with php on IIS

$
0
0

Hello,

I have a php installed on iis servr on windows server 2012.. The php script has been executed successfully on the IIS erver . I want to integratie mysql server or sql server studio with the php script . i have installed both mysql server and sql server studion on the same server with iis.

I read an article that guided me on how to install mysql server community installer for php. I have created a database named 'student'. I created a user 'ict' and provisioned this user for this database. I equally granted  all the privileges for this user. I dont know if i did t correctly.

How can i verify the database connection in the php scritp ?


SQLSERVER 2008 R2 - PHP 5.4 - PDO 3.0 - Stored procedures - Parameter output bad

$
0
0

Hello,

i use php 5.4 , PDO 3.0, sqlserver 2008 r2, windows 2008 r2, IIS 7.5 with store procedure and output parameter.

it work fine when i call store procedure with output parametyer like microsoft sample:http://technet.microsoft.com/en-us/library/ff628166(v=sql.105).aspx

<?php
   $database = "AdventureWorks";
   $server = "(local)";
   $dbh = new PDO( "sqlsrv:server=$server ; Database = $database", "", "");

   $dbh->query("IF OBJECT_ID('dbo.sp_ReverseString', 'P') IS NOT NULL DROP PROCEDURE dbo.sp_ReverseString");
   $dbh->query("CREATE PROCEDURE dbo.sp_ReverseString @String as VARCHAR(2048) OUTPUT as SELECT @String = REVERSE(@String)");
   $stmt = $dbh->prepare("EXEC dbo.sp_ReverseString ?");
   $string = "123456789";
   $stmt->bindParam(1, $string, PDO::PARAM_STR | PDO::PARAM_INPUT_OUTPUT, 2048);
   $stmt->execute();
   print $string;   // Expect 987654321
?>

BUT it don-t work when i use one or more select, insert, update in my store procedure before return result. In this case, values output are anything and the return value is lost.

Can you help me ?

Thanks

SQLServer issue

$
0
0

When trying to install Nop Commerence, i'm getting a error accessing 'master'  Database.

I don't think its a permission issue in SQL, because unlike what i've seen others doing when i do a Google search I CAN create databases just fine from SQL Server 2014 just fine under Windows 7

I've also tried granting permission for 'Modify' under wwwroot folder thinking it was somehow related.. Permissions are 'Read & Execute', 'Modify', Read' & 'Write' for Users, IIS_IUSRS and DefaultAppPool. So its only Nop Commence not talking.. 

I also assume this is different situation than others because I CAN create database manually in SQL  Management Studio

I'm authenticating to SQL via Windows authentication, and telling Nop-Commerence to do the same.. Password is also correct.

Any solution?

Unable to connect to SQL via PHP5.2

$
0
0

Hi there,

I've been looking for a solution to this problem for a week now but i can't seem to find one.

OVERVIEW:   I have a live server and a local server. I am able to connect to a live server but not on my local. I was not the one setting up the LIVE server. 

I tried all the solutions I've found on internet but i couldn't still make it work. The problem must lie on the server configuration since i am able to connect to the LIVE server.

Here are my solutions but didn't work:

1. Enabled the TCP/IP through Configuration Manager with TCP port 1433 in IPALL and restarted the SQL instance services. I used the local IP WITHOUT port when connecting to sql server.

2. I also tried specifying the port number after the IP  and restarted the SQL instance services but it didn't work. 

3. I tried using the HOSTNAME\INSTANCE_NAME but still not working.

NOTE: I can connect to both server using MSSQL Server Management Studio.

Any help from you would be greatly appreciated. Thanks in advance.

Microsoft Drivers for PHP 5.6 and SQL Server 2016 for Centos 7

$
0
0

Hi,

Is there any solution to install Microsoft SQL Drivers with php 5.6 on centos 7

problem is this my project based on php version 5.6 and Operating system is Centos 7 we've tried to install SQL driver with php(5.6) and they are not installing.

p.s we are bound to update PHP version and have to stay on 5.6

kindly update regarding this issue.

thanks

cannot get my PHP app to connect to sql server

$
0
0

Hello, I have been trying to get my application to connect to sql server v17, while developing in Visual Studio 2017.  When I run my application this is the error I get:

Error connecting to SQL ServerPDOException: could not find driver in C:\Users\v-datatu\source\repos\OccurrenceTracker\OccurrenceTracker\model\database.php:4 Stack trace: #0 C:\Users\v-datatu\source\repos\OccurrenceTracker\OccurrenceTracker\model\database.php(4): PDO->__construct('sqlsrv:Server=c...', NULL, NULL) #1 C:\Users\v-datatu\source\repos\OccurrenceTracker\OccurrenceTracker\index.php(3): require('C:\\Users\\v-data...') #2 {main}

when I run phpinfo() I do not see any references anywhere to MSSQL. 

Also my phpinfo() shows I have php version 7.1.19

This is where the php.ini file that is being loaded it

Configuration File (php.ini) Path C:\WINDOWS
Loaded Configuration File C:\Program Files (x86)\IIS Express\PHP\v7.1\php.ini

and this is how my php.ini file has been edited

[MSSQL]
mssql.allow_persistent=On
mssql.max_persistent=-1
mssql.max_links=-1
mssql.min_error_severity=10
mssql.min_message_severity=10
mssql.compatability_mode=Off
mssql.secure_connection=Off
zend_extension = C:\Program Files (x86)\iis express\PHP\v7.1\ext\php_xdebug.dll
;zend_extension = C:\xampp\php\ext\php_xdebug-2.6.1-7.2-vc15.dll
extension_dir="C:\Program Files (x86)\iis express\PHP\v7.1\ext\"
extension=php_pdo_sqlsrv_71_nts.dll
extension=php_sqlsrv_71_nts.dll

I downloaded the drivers from https://github.com/Microsoft/msphpsql and put them in C:\Program Files (x86)\iis express\PHP\v7.1\ext\

any help or ideas would be appreciated this is the first time I am trying to develop a PHP app in VS with sql server

Ubuntu 18.04 sqlsrv_connect works on server not in remote browser

$
0
0
I installed all the extensions needed to use sqlsrv on ubuntu 18.04 following one of the microsoft doc tutorials. Everything works great on the server when I run my scripts. When I open a browser from a local worksattion that has access to the server I get 'Uncaught Error: Call to undefined function sqlsrv_connect() '......I go back to the server and run the same page on the server and it works fine. Any ideas?

Pivot table

$
0
0

Following is my code snippet.

select distinct *
from
        rpt_pivot_data
            pivot (
                    sum(numeric_6)
                    for (numeric_3)
                    in ('Q1' as "1Q",
                        'Q2' as "2Q",
                        'Q3' as "3Q",
                        'Q4' as "4Q",
                        'no_show_Q1',
                        'no_show_Q2',
                        'no_show_Q3',
                        'no_show_Q4',
                        'ytd' as "YTD")
                   )
order by numeric_1

I want the 'no_show_Q1' to appear under 1Q,'no_show_Q2' to appear under 2Q, 'no_show_Q3' to appear under 3Q, and 'no_show_Q4' to appear under 4Q.

Please suggest as to how I can accomplish this task. Thank you in advance!


Using Driver SQL Server + PHP : Error when create and select a temp table (host web on Window is OK , on Linux error)

$
0
0

Hi ALL,

- First,sorry about my English.

- As title, when i host my web on Linux Server and connect to SQL Server (host on Window Server) , i excute query in php :

CREATE TABLE dbo.#Cars ( 
   Car_id int NOT NULL ,
   ColorCode varchar(10),
   ModelName varchar(20),
   Code int, 
   DateEntered datetime 
 ) 

	INSERT INTO dbo.#Cars (Car_id, ColorCode, ModelName, Code, DateEntered) 
	VALUES (1,'BlueGreen', 'Austen', 200801, GETDATE())

-I run tool SQL Server Profiler and seen it was run this query but check in Sql Server -> System Database - > tempdb -> Temporary Tables  isn't exist table #Cars ?? . Excute this query in SQL Server is OK.

-I host my WEb on Window Server is OK,not happen this error .

-I using driver pdo_dblib + PHP 5.6 

Thks for read.

LongMT

having trouble connect to php server

$
0
0

I am trying to connect to a SQL server using php.

The server I am trying to connect to is using Windows Server 2012 R2 with Microsoft SQL Server 2012.

The development machine is running php version 7.2.13, with Microsoft Drivers 5.3 for PHP for SQL Server installed. It is running an IIS web server.

I am trying to connect using Active Directory authentication. I am using code that I found on here:

https://docs.microsoft.com/en-us/sql/connect/php/azure-active-directory?view=sql-server-2017

Here is my code:

<?php  

// Now connect to an Azure SQL database by setting Authentication to ActiveDirectoryPassword
$azureServer = "vgissql";
$azureDatabase = "dbo";
$azureUsername = "myuid";
$azurePassword = "mypassword";
$connectionInfo = "Database = $azureDatabase; Authentication = ActiveDirectoryPassword;";

try
{
    $conn = new PDO( "sqlsrv:server = $azureServer ; $connectionInfo", $azureUsername, $azurePassword );
    echo "Connected successfully with Authentication=ActiveDirectoryPassword.\n";
    $conn = null;
}
catch( PDOException $e )
{
    echo "Could not connect with Authentication=ActiveDirectoryPassword.\n";
    print_r( $e->getMessage() );
    echo "\n";
}

?> 

If I try to open the php file in a web browser, I get this:

Could not connect with Authentication=ActiveDirectoryPassword. could not find driver

Any ideas what is going on?

SQLSRV Driver for PHP 7.3

$
0
0

Hi,

I am unable to find SQLSRV Driver for PHP 7.3. I've Xampp installed which has PHP 7.3 version. SQLSRV driver versions 7.1, 7.2 are not compatible with PHP 7.3. Any idea where can I find correct driver?

Thank you.


ZulfiqarMD

Using Temp table in stored procedure causing memory load

$
0
0

Hi

I have a complex and dynamic stored procedure which included a CTE. This stoed procdure was working fine with php but took lot of time to return dataset(16 seconds for 2015 rows). After using Functions it took around 6 seconds which also made reporting very slow.

Now I have replaced CTE with Temp table and query executes in one second for 2015 rows. But its is causing load on web application(designed in php) giving error "Memory limit of 10240 KB exceeded for buffered query".

Why using temp table causing load on web application?

This is the format of stored procedure

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER  PROCEDURE xyz

   @ID INT  = NULL
   ,@StartDate DATETIME = NULL
   ,@EndDate DATETIME = NULL

AS
BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from    -- interfering with SELECT --statements.
    SET NOCOUNT ON;
    SET ANSI_WARNINGS OFF;

    IF OBJECT_ID('TempDb..#Resultstemp', 'U') IS NOT NULL DROP TABLE #Resultstemp;

                CREATE TABLE #Resultstemp
                (
                    Date DateTime null,
                    ID INT null,
                    Name VARCHAR(1000)  COLLATE SQL_Latin1_General_CP1_CI_AS null ,
                    Organisation VARCHAR(1000)  COLLATE SQL_Latin1_General_CP1_CI_AS null

                         ............................................................

                );

                INSERT INTO #Resultstemp

                SELECT
                                XYZ

                FROM Tables;

        SELECT * FROM #Resultstemp
    SET NOCOUNT OFF;    
END

Please help me around the issue.

Many Thanks!

Inderjeet Kaur


[Microsoft][ODBC Driver 17 for SQL Server]Cannot use Authentication option with Integrated Security option.

$
0
0

I am trying to connect to a Microsoft SQL Server with PHP using Active Directory Authentication.

<?php

$serverName = 'vgissql';
$connectionInfo = array('Database'=>'gis', "Authentication"=>'ActiveDirectoryPassword');

$conn = sqlsrv_connect($serverName, $connectionInfo);
if ($con){
    echo "Connection established";
}else{
    echo 'Connection failed<br>';
    die(print_r(sqlsrv_errors(), True));
}

?>

Connection failed
Array ( [0] => Array ( [0] => FA001 [SQLSTATE] => FA001 [1] => 0 [code] => 0 [2] => [Microsoft][ODBC Driver 17 for SQL Server]Cannot use Authentication option with Integrated Security option. [message] => [Microsoft][ODBC Driver 17 for SQL Server]Cannot use Authentication option with Integrated Security option. ) [1] => Array ( [0] => FA001 [SQLSTATE] => FA001 [1] => 0 [code] => 0 [2] => [Microsoft][ODBC Driver 17 for SQL Server]Cannot use Authentication option with Integrated Security option. [message] => [Microsoft][ODBC Driver 17 for SQL Server]Cannot use Authentication option with Integrated Security option. ) )

Any ideas?

Viewing all 391 articles
Browse latest View live


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