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

NULL values and data truncation due to automatic data types conversion

$
0
0

We are migrating from FreeTDS to Doctrine PDOSQLSrv or SQLSrv (trying both at the monent) and have encountered the problem with the data truncation of the fields that are not updated.

Our update statements look like

update tbl
set
	field1 = isnull(?, field1)
	, field2 = isnull(?, field2)
where id = ?

We have investigated that it is caused by the data type conversion. FreeTDS runs the queries as is, so when you pass the NULL value, NULL is used. However PDOSQLSrv and SQLSrv run queries with sp_prepexec stored procedure, so it is not NULL any more, but a NULL-valued variable. Unfortunately both libraries convert PHP nulls to char(1) (in documentation https://docs.microsoft.com/en-us/sql/connect/php/default-sql-server-data-types it is said to be varchar(1) but still it doesn't help, I can see char(1) in the Profiler), so when the field is not updated and we pass NULL, it truncates the data. 

So the question is how to pass null correctly?  


How to set TimeOut for execution the stored procedure from PHP

$
0
0

Hi,

How do I set the TimeOut  for EXEC the Stored Procedure from PHP

Because i am using php to call sql server Stored Procedure,
for ex:
 "EXEC SP_Name"

some times its taking too long time, so the php page shows 500 Internal server error.

If possible to set the time limit the SP was stopped then i show the error description etc...

how do i fix this issue?

Thanks in Advance.




Message authentication code

$
0
0

Hello Everybody,

Please can you help me to find out the information in SQL Server 2012.

MAC of authentication information

1. Implementation level of MAC

2. Protocol

3.Cipher Suite 

4. Version

5. Key Length 

MAC of data stream

1. Implementation level of MAC

2. Protocol

3.Cipher Suite 

4. Version

5. Key Length 

SQL Server Compatibility

$
0
0

Hi,

Is PHP 7.2.2 compatible with the Microsoft Drivers for PHP for SQL Server?

Greetings

php 7.0 sqlsrv_connect to SQL 2008 R2

$
0
0

Hi,

Could someone help us resolve the issue, thank in advance? We are using php 7, sql server 2008 r2 on windows server 2008 r2 sp1, iis 7.5.

The issue is we are upgrading code to work with php 7, earlier there was mssql_connect and mssql_* functions that were working so far but not anymore on php 7. So we are now trying to make similar function sqlsrv_connect and sqlsrv_* to work, it does not work at the moment we are stuck with this error dump. Please notice that we have already installed the Microsoft ODBC Driver as mentioned in the error message but still we receive the same error.

Here is testcode:

$serverName = "serverName"; 
$dbusername = "dbusername";
$dbpassword = "dbpassword";
$dbname = 'dbname';

$connectionInfo = array( "Database"=>$dbname, "UID"=>$dbusername, "PWD"=>$dbpassword);

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

if( $link !== false ) {
	echo "Connection established.".PHP_EOL;
}
else{
	die( print_r( sqlsrv_errors(), true));
}




Here is error message:

Array(
	[0] => Array
		(
			[0] => IMSSP
			[SQLSTATE] => IMSSP
			[1] => -49
			[code] => -49
			[2] => This extension requires the Microsoft ODBC Driver 11 or 13 for SQL Server. Access the following URL to download the ODBC Driver 11 or 13 for SQL Server for x64: http://go.microsoft.com/fwlink/?LinkId=163712
			[message] => This extension requires the Microsoft ODBC Driver 11 or 13 for SQL Server. Access the following URL to download the ODBC Driver 11 or 13 for SQL Server for x64: 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
		)
)


Here is screenshot of odbc datasource:
https://i.stack.imgur.com/PoQAK.png


Here are screenshots of php config
sqlsrv config

https://i.stack.imgur.com/4BEpm.png

odbc conf

https://i.stack.imgur.com/zsShM.png

pdo

https://i.stack.imgur.com/f1P9r.png

One more thing, if we need to install odbc drivers anyways why should one bother with Microsoft drivers. Is there anythnig I am missing?

Showing an SQL Server table in an html table php

$
0
0

Hi,

I have connected to my SQL database using SQLSRV driver when I try to display a Column that contains a DateTime value, the column is empty and any decimal value is shown with 2 extra 0's.

Is there something I have to do in order to display a column value of DateTime in an HTML table using PHP?


CuriousCoder


How to retrieve data from an sql server db using a stored procedure php

$
0
0

Hi,

I am struggling to understand how to get data from my SQL server DB using a stored procedure, the stored procedure requires that I pass it the parameter of 'date', then I wish to populate an HTML table with the list of rows that it will return.

I successfully connected to my DB and retrieved an entire table and displayed it in an HTML table but the syntax confuses me when trying with a Stored Proc, can anyone help?

Here is my code:

<?php
/* Empty data array */
$trackData = array( );

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

$credentials = array
(
  'UID'       => 'user',
  'PWD'       => 'password',
  'Database'  => 'myDB',
  'ReturnDatesAsStrings' =>1

);

$date = date('d-m-Y');
$params = array( $date, SQLSRV_PARAM_IN ) ;
$connection = sqlsrv_connect( $server, $credentials );


/* Get sql data */
global $connection;
$sqlForTrack ="SPGetTracks";
$queryForTrack = sqlsrv_query( $connection, $sqlForTrack, $params );


/* Handle sql errors if retuned */
if( $queryForTrack === false )
{
        echo ("failed to load query");
        die( '<pre class="error">' . print_r( sqlsrv_errors(), true ) . '</pre>' );
}

/* Handle sql response for track data */
if( sqlsrv_num_fields( $queryForTrack ) )
{
        echo "<thead><tr><th>Tracks</th></tr></thead>";

        while( $row = sqlsrv_fetch_array( $queryForTrack, SQLSRV_FETCH_ASSOC ) )
        {
                echo "<tbody>";
                echo "<tr>";
                echo "<td>" . $row['Tracks'] . "</td>";
                echo "</tr>";
                echo "</tbody";

        }
        echo "</table>";
}

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


CuriousCoder

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


PDO Specific module can't be found

$
0
0

Hello,

I am trying to install the PDO_SQLDRV, and when i run php --ini I get "the specified module can not be found" for these two files: php_pdo_sqlsrv_71_nts_x64.dll & php_sqlsrv_71_nts_x64.dll.  I found these files from the SQLSRV43 download, which automatically extracted dll's to this file path (C:\wamp\bin\php\php7.1.9\ext).  In PHP.ini this is the extension_dir.

In the Dynamic Extensions section, I put this in

extension=php_sqlsrv_71_nts_x64.dll 
extension=php_pdo_sqlsrv_71_nts_x64.dll 
What am I doing wrong?  I am running PHP 7.1.9.

I am not able to check whether user is authenticated or not using php and sql server.

$
0
0

I have a login.html then action is logincheck.php and here

login check.php

<?php  
    $uname = $_POST['username'];
    $pword = $_POST['password'];


$serverName = "192.168.0.153,1433";
$connectionInfo = array( "Database"=>"test", "UID"=>"sa", "PWD"=>"password");
$conn = sqlsrv_connect( $serverName, $connectionInfo);

if( $conn )  

$sqlquery="select * from emp where username='$uname' and password='$pword'";
$query = sqlsrv_query($conn,$sqlquery);


$row=sqlsrv_fetch_array($query);
$count=sqlsrv_num_rows($query);
echo $query ;

if ($count === false )
{

header('Location:/');

}
else
{
header('Location: /main.html');
}  
sqlsrv_close($con);

}else{
echo"<h1 >Database Connection Error...</h1>";
}
?>

When i entered correct username password it have to go main.html page but it is going to same page itself.

Connection was established but i am thinking that prblem with sqlsrv_query or fetch .

Can anyone solve my problem.

Thank you

Error 1704 Microsoft SQL server 2008 R2 Native Client

$
0
0
Hello, I am attempting to install Tableau on my laptop and in the middle of the installation I receive an error 1704. An installation for Microsoft SQL server 2008 R2 Native Client is currently suspended. You must undo the changes made by the installation to continue. Do you want to undo those changes? When I select 'yes' nothing happens. What can be done in order for installation to work? I am using Windows 10 Version 1709 (2017).

Big data, PHP and cursors

$
0
0

Environment:

CentOS 7.4 with PHP 7.0.10 running from the command line
SQLSRV driver version is 4.3.0 (according to 'php --ri sqlsrv')
Microsoft SQ0L Server version 2014

I am developing a PHP solution to query SQL server database that will return millions of records so I can't use my standard approach of fetching the entire result set into an array. In addition to this, I need to do some additional calculations and subtotaling of the result data. I am thinking the proper approach is to use cursors. So, per the documentation, I added PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL and PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_STATIC to my prepare statement but I get an error when I try to use fetch(PDO::FETCH_ASSOC, PDO::FETCH_ORI_ABS, -1) or fetch(PDO::FETCH_ASSOC, PDO::FETCH_ORI_PRIOR)

PHP Fatal error:  Uncaught PDOException: SQLSTATE[HY106]: [Microsoft][ODBC Driver 13 for SQL Server]Fetch type out of range in script.php

I don't have problem when I use fetch(PDO::FETCH_ASSOC, PDO::FETCH_ORI_NEXT) or fetch() without arguments. I haven't modified the query at all to use cursors and maybe that's my problem. The query doesn't use stored procedures. It's is basically a complex select query

Any ideas on what I could be doing wrong?
Thanks, Todd

Unexpected error "New transaction is not allowed because there are other threads running in the session"

$
0
0
Hi,

I've found a problem that appears to be a driver or database bug.

While fetching a resultset in non-transactional context it is not allowed to start a transaction - this is well-known, you'll get a "New transaction is not allowed because there are other threads running in the session."

However, when using a specific type of COUNT()-query that should only have exactly one result record, the resultset appears to be left open even when sqlsrv_fetch_array() has been called thus leading to unexpected failures when calling sqlsrv_begin_transaction() afterwards.

I have written a reproduction script, please check:

###################################################################
<?php

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) . ']';

    /*
     * symptoms:
     * - when trying to open a transaction, this error occurs:
     * "New transaction is not allowed because there are other threads running in the session."
     * even though the resultset was fetched entirely!
     *
     * required column properties for physical tables:
     *  - contains at least one NULL value
     *  - column has no index
     */
    $query = <<<SQL
        SELECT COUNT(*) AS num_records FROM
        (
            SELECT  MIN(foo.bar) AS baz
            FROM  
            (
                SELECT NULL AS bar
                
                  UNION
                  
                SELECT 'bar' AS bar
            ) foo
            
            UNION
            
            SELECT  NULL AS bar
        ) foobar
SQL;
    
    $ps = sqlsrv_prepare($db_conn, $query, array(), array('Scrollable' => SQLSRV_CURSOR_FORWARD));
    if (!$ps) {
        throw new Exception('no ps');
    }
    if (!sqlsrv_execute($ps)) {
        throw new Exception('execute failed');
    }
    
    $result = sqlsrv_fetch_array($ps);
    var_dump($result);
    
    // uncomment to workaround the unexpected error below:
    //$result = sqlsrv_fetch_array($ps);
    //var_dump($result);
    
    // this fails but should not fail
    if (!sqlsrv_begin_transaction($db_conn)) {
        throw new Exception(print_r(sqlsrv_errors(), true));
    }
    
} 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('no link');
    }

    return $conn;
}
###################################################################

Expected result: no error when calling sqlsrv_begin_transaction().
Actual result: "New transaction is not allowed because there are other threads running in the session."

php version: [7.0.15]
sqlsrv_client_info: [
(
    [DriverDllName] => msodbcsql11.dll
    [DriverODBCVer] => 03.80
    [DriverVer] => 12.00.5579
    [ExtensionVer] => 4.1.8930.1
)

Best regards
Lars

error installing : fails to create SQLEXPRESS00 user on domain controller due to password policy restrictions

$
0
0

Title says it all...

I go to install from the command line, specifying passwords for all of the default accounts and this error pops up, preventing the install.

I've tried creating and using a domain user, but that gives the same error, creating a SQLEXPRESS00 "local" user.

Anyone know what the default password is for the SQLEXPRESS00 user that the installer creates, or how to specify it, or am I going down the wrong track entirely?



64 bit Microsoft Drivers for PHP 5.6 for SQL Server

$
0
0

Hello everyone,

Can anyone please tell where to find the official release of "64 bit Microsoft Drivers for PHP 5.6 for SQL Server" (php_sqlsrv_56_ts.dll and php_pdo_sqlsrv_56_ts.dll - both 64 bit).
I searched for it but couldn't find it anywhere.
The following link contains the official 32 bit drivers:
https://www.microsoft.com/en-us/download/details.aspx?id=20098

  • Version 3.2 supports PHP 5.6, 5.5, and 5.4 on Windows

Any help would be appreciated.

Thanks,

Sam


how to add a picture inside a table

$
0
0

Am new in PHP I want to show a picture inside a table

The information stored in the table has part of the image path

So far, my table looks like

<?php foreach($viewmodel as $item) : ?><tr><td id="c_01" align="center" > <small><?php echo $item['purno']; ?></small></td><td id="c_02" align="center"><small><?php echo $item['vendno']; ?></small></td><td id="c_03" align="center"><small><?php echo $item['purdate']; ?></small></td><td id="c_04" align="left" ><small><?php echo $item['item']; ?></small></td><td id="c_05" align="right" ><small><?php echo number_format($item['qtyord'],0,".",","); ?></small></td><td id="c_06" align="right" ><small><?php echo number_format($item['qtyrec'],0,".",","); ?></small></td><td id="c_07" align="center" > <img src=$host.$item['imgfile']> </td> </tr>            	<?php endforeach; ?> 	

Unfortunately, I can not get the picture to display

What am I doing wrong?


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

Performance issue

$
0
0

we run two SQL instance sql 2012 on windows 2012 VM.  one instance is slow and other is OK.  there is no issue like blocking or anything related to SQL database. also there is no resource contention (cpu , memory or network or disk. 

they are about same data on both instance . they are asking me why this instance is slow , other one is good . i am stumbled i have no answer .  i compared the server config are same etc. 

it has 4 logical processor , 8 gig memory , 3gig allocated for each instance and rest for OS.

My PHP query to my SQL table is not returning any results.

$
0
0

So i connect to the database just fine. The only thing is that it keeps failing on the query. Here is my simple query code.

Am I forgetting something or missing something that is currently eluding me? I have tried many different ways and it all returns as "It failed"

      

include 'connect.php';

$sql = "SELECT 'url' FROM 'my_videos'";
   $result = mysqli_query($conn, $sql);

   if(mysqli_num_rows($result) > 0)
   {
while($row = mysqli_fetch_assoc($result))
{
echo 'it worked!'; 
}
   }
else 
{
echo 'Keeps failing'; 
echo $row['url'];
}

include 'connclose.php';

Pass Windows Domain Creds from Linux PHP

$
0
0

I need to pass a Windows AD Service Account to the SQL Server to login from a PHP application running on Linux/Apache/PHP using the sqlsrv driver from pecl.php.net (https://pecl.php.net/package/sqlsrv).   

I know how to do this on Windows using IIS, which is just a simple matter of changing the IIS App Pool to run as the service account.  

I cannot figure out how to do this from the Linux system.  

I have googled and found many articles and postings on many different sites, which talk about joining the linux box to the windows domain, and then configuring kerberos on the linux box, but I have tried it all, and none of it works for me.  Perhaps I am just missing something simple, or over complicating things. 

The driver works just fine if I pass in a SQL user/pwd combination.  So, I dont think its a driver issue, but more a configuration issue.

Has anyone gotten this to work? 

Is it possible to get this to work?

Thanks

Rick

Viewing all 391 articles
Browse latest View live


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