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

fieldmetadata of greek database not showing right

$
0
0

I have a greek database in sql server 2008 with the character columns set to nvarchar.When i connect to the database from php i have set Characterset to UTF-8 and in the header of the html files charset="utf-8".When i retrieve data from the database it shows fine in the browser,but if i want to retrieve the column names with sqlsrv_field_metadata(), the name fields are shown with question marks.

If i retrieve the column names from the infromation_schema.columns view they are shown fine.

What can i do to get the column names from the sqlsrv_field_metadata()?


Is PHP capable of handling all SQL Server syntax and commands?

$
0
0

I'm running into database errors when running a query via php and pdo. It runs fine on SQL Server, but not through my php application. 

You can see the query that is failing here http://stackoverflow.com/questions/27262644/how-can-i-troubleshoot-a-raw-mssql-query-that-runs-fine-on-sql-server-but-fails

I'm at my wits end. I need to be able to execute this query for a project which I am urgently completing, however no matter what I do, it is failing in PHP.

Can't find compatible drivers for PHP

$
0
0

I’m running Windows 7 Pro, SQL Server 2012, and installed xampp for PHP version 5.6.3. Thread safety is enabled. I cannot find Microsoft SQL Server drivers that are compatible with this version. I’m using the following from SQLSRV31.EXE in my PHP extensions:

extension=php_pdo_sqlsrv_55_ts.dll

extension=php_sqlsrv_55_ts.dll

 

but I’ve tried all the available drivers and get variations of the same message when trying to run:

"PHP Startup: sqlsrv: Unable to initialize module Module compiled with module API=20100525 PHP  compiled with module API=20131226. These options need to match."

I can’t find any MS drivers for 5.6. Is there a solution? Do I need to  install the earlier versions of xampp?


Problems connecting php5.5 to sql server with php_pdo_sqlsrv_55_ts.dll

$
0
0

I am trying to retrieve code I last touched a couple of years ago to connect to a sql server database.  I have a little test utility to do that

<?php   $serverName = 'ROO\SQLEXPRESS';    $database = "PAS_Live";   // Get UID and PWD from application-specific files.   

$uid = "accu_app";   $pwd = "xxxxx";   try {      $conn = new PDO( "sqlsrv:server=$serverName;Database = $database", $uid, $pwd); $conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );    }   catch( PDOException $e ) { die( "Error connecting to SQL Server: $e" );    }   echo "Connected to SQL Server\n"; ?>


This used to work fine with the old version of the drivers.  Since time has moved on, I am trying this again with the latest drivers contained in the SQLSERVER31.EXE file that you can download.  In particular I have set up php5.5 to run with the extension file php_pdo_sqlsrv_55_ts.dll that that file contains.

Whe I run the little test program, it flags up this error (only partially listed it)

'SQLSTATE[IMSSP]: This extension requires the ODBC Driver 11 for SQL Server to communicate with SQL Server...'

I tried downloading the ODBC driver given in the link in the full message (which doesn't point to the driver - but you can find the download link from that link if you search for it), but it refused to install.  I presume that is because, according to my  Data Sources(ODBC)  (run from Administrative Tools), I already have a driver"Sql Server Native Client 11.0" installed.

What am I supposed to do to get this working.  There is absolutely no documentation with the driver that I can find to explain how this new driver works.  Does the connection string change for instance? Or can I uninstall an old client to install a new one.

I am currently doing all of this on Windows 7 Home Premium, but this is really just a test install for the long term plan to move it all to a Server 2011 installation.


SQL Server 2008 R2 backup problem with Sector Size.

$
0
0

I have restored a SQL Server 2008 R2 to my local development system with SQL Server 2008 R2 SP1. After restoring the database, I tried to do a backup and received the message:

How can I solve this problem?

Thanks,

Doug MacLean

Difference between 3.1 and 3.0.1 version

$
0
0
Wich are the differences between both version? Regards

How to catch multi language's data in MSSQL and data isn't garbled

$
0
0

Hi everyone, I'm Taiwanese PHP developer, sorry for my poor English.

I have 3 language's data:Simplified Chinese,Traditional Chinese, and English in our mssql2012 database.

If I want to use ADODB to catch data,The Simplified Chinese and Traditional Chinese will be garbled.

I try to use mb_convert_encoding($data,'UTF-8','BIG-5'), the Traditional Chinese is ok, but Simplified Chinese is still garbled.

Do anyone have suggestion?

This is my output:

Array
(
    [0] => Array
        (
            [0] => ZHS2
            [1] => ?体中文
            [2] => 123
        )

    [1] => Array
        (
            [0] => ZHS3
            [1] => 翻?
            [2] => 123
        )

    [2] => Array
        (
            [0] => ZHS
            [1] => ?体中文
            [2] => Chinese Simplified
        )

    [3] => Array
        (
            [0] => ZHT
            [1] => 繁體中文
            [2] => Chinese Traditional
        )

    [4] => Array
        (
            [0] => US
            [1] => English
            [2] => English US
        )

)

Here is my code:

<?php
include('adodb5/adodb.inc.php');

	function encoding_data($results){
		foreach($results as $key1 => $result){
			foreach ($result as $key2 => $arr_str){
				if(is_integer($key2)){
					//unset($results[$key1][$key2]);
					//echo $key2."=>".$arr_str."<p />";
				}else{
					//echo $key2."=>".$arr_str."<p />";
					$results[$key1][$key2] = mb_convert_encoding($arr_str, 'UTF-8','BIG-5');
				}
				$results[$key1][$key2] = mb_convert_encoding($arr_str, 'UTF-8', 'BIG-5');
			}
		}
		return $results;
	}

	$sql = $_REQUEST['sql'];
	$usedb = $_REQUEST['usedb'];

	if($sql==""){

		$sql = "select * from HCP";

	}

	if($usedb == ""){

		$usedb ="oci8";

	}

	if($usedb == "mssql"){

		$hostname = "Driver={SQL Server};Server=XXXX,XXXX;Database=XXXX;CharacterSet=UTF-8;UID=XXXX;PWD=XXXX";
		//$port = XXXX;
		$dbname = "XXXX";
		$username = "XXXX";
		$pw = "XXXX";

		$mssqlconn = &ADONewConnection ('odbc_mssql');
		//define connection string, specify database driver
		$mssqlconn->Connect($hostname, $username, $pw , $dbname);
		$mssqlconn->debug = false;

		$results = $mssqlconn->GetArray($sql);
		$results = encoding_data($results);

		echo "<pre>",print_r($results),"</pre>";
		print_r($usedb);
?>


Stored procedure timing out - was working fine.

$
0
0

I have a stored procedure which all of a sudden started to time out when called from the data access method for no apparent reason.  Here's the situation:

Its been running fine since its creation about 2 months ago.

It always returns the same fixed number of rows (about 6k rows), the only thing that changes are some of the values in those rows.

Its just a large sql statement, no cursors or anything out of the ordinary.

This has happened twice.  each time it was running find until I ran an update statement to change some of the values. in this case I set a bit column from 0 to 1, and set a date value in a datetime column to all 6k rows. the next time the application executed it, it started to time out.

it runs fine from SSMS where I execute it from the query window.  from here it executes instantly as expected.

the app code that executes the sproc where its timing out is:

qlConnection conn = null;
conn = DBConnectoinHelper.GetDBConnection();
conn.Open();
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = "dbo.spIssue_LTE_lst ";
cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.Parameters.Add("@Df_Prj_Id", SqlDbType.UniqueIdentifier).Direction = ParameterDirection.Input;
cmd.Parameters["@Df_Prj_Id"].Value = id;
SqlDataReader rdr = cmd.ExecuteReader();

Here's the exception I get in this method when running the code above:

Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding. "at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
   at System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
   at System.Data.SqlClient.SqlDataReader.get_MetaData()
   at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
   at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, SqlDataReader ds)
   at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite)
   at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
   at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
   at System.Data.SqlClient.SqlCommand.ExecuteReader()
   at DataServices.Issue_LTE_DataServices.Issue_LTE_GetListByFK(Guid id)"

The first time this happened, I deleted the sproc and then recreated it, then it ran OK again.  any idea what's happening here and how to trouble shoot/resolve it?

Thank you.


how connect to SQL Server 2008 R2 using php from windows 10

$
0
0

hi

SqlServer databaseI was abletoconnect on Windows8.1, Windows10, butthefollowing error:

SQLSTATE[IM003]: Specified driver could not be loaded due to system error 126: The specified module could not be found. (ODBC Driver 11 for SQL Server, C:\Windows\SysWOW64\msodbcsql11.dll).1


Please helptosolvemyproblem.

Thanks :)

SQL Server 2008 R2

Windows 10

PHP V : 5.6



Zend Framework 1.10.3 and PDO_MSSQL

$
0
0

Hi,

I try to connect from the ZendFramework 1.10.3 via php_pdo_sqlsrv_52_nts.dll without success.

phpinfo shows me:

PDO section:

PDO drivers   / sqlsrv

pdo_sqlsrv section:

pdo_sqlsrv support  / enabled

 

I try to conect using the Adapter Factory Method with a  Zend_Config Objekt.

Config.ini:

[general]
db.adapter = PDO_Mssql
db.params.host = "localhost"
db.params.username = WEBUser
db.params.password = WEBUser
db.params.dbname = ZFiA_Places

Bootstrap:

$db = Zend_DB::factory($config->db);

 

I always get this Errors:

Error: The mssql driver is not currently installed
#0 C:\PHP\includes\Zend\Db\Adapter\Pdo\Mssql.php(137): Zend_Db_Adapter_Pdo_Abstract->_connect()
#1 C:\PHP\includes\Zend\Db\Adapter\Abstract.php(448): Zend_Db_Adapter_Pdo_Mssql->_connect()
#2 C:\PHP\includes\Zend\Db\Adapter\Pdo\Abstract.php(238): Zend_Db_Adapter_Abstract->query('exec sp_columns...', Array)
#3 C:\PHP\includes\Zend\Db\Adapter\Pdo\Mssql.php(237): Zend_Db_Adapter_Pdo_Abstract->query('exec sp_columns...')
#4 C:\PHP\includes\Zend\Db\Table\Abstract.php(823): Zend_Db_Adapter_Pdo_Mssql->describeTable('places', NULL)
#5 C:\PHP\includes\Zend\Db\Table\Abstract.php(862): Zend_Db_Table_Abstract->_setupMetadata()
#6 C:\PHP\includes\Zend\Db\Table\Abstract.php(969): Zend_Db_Table_Abstract->_setupPrimaryKey()
#7 C:\PHP\includes\Zend\Db\Table\Select.php(100): Zend_Db_Table_Abstract->info()
#8 C:\PHP\includes\Zend\Db\Table\Select.php(78): Zend_Db_Table_Select->setTable(Object(Places))
#9 C:\PHP\includes\Zend\Db\Table\Abstract.php(1005): Zend_Db_Table_Select->__construct(Object(Places))
#10 C:\PHP\includes\Zend\Db\Table\Abstract.php(1303): Zend_Db_Table_Abstract->select()

I thinkthe Problem is that the PDO_Mssql Driver is named in phpinfo() with sqlsrv and not Mssql.

Have anyone an Idea whats wrong???

How can I get this thing running.

 

The "normal" connection over the PDO driver like this is working.

 

   $serverName = "(local)";
   $database = "AdventureWorks";

   // Get UID and PWD from application-specific files.
   $uid = 'WEBUser';
    $pwd = 'WEBUser';

   try {
      $conn = new PDO( "sqlsrv:$serverName", $uid, $pwd, array( 'Database' => $database ) );
      $conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
   }

   catch( PDOException $e ) {
      die( "Error connecting to SQL Server" );
   }

   echo "Connected to SQL Server\n";

   $query = 'select * from Person.ContactType';
   $stmt = $conn->query( $query );
   while ( $row = $stmt->fetch( PDO::FETCH_ASSOC ) ){
      print_r( $row );
   }

   // Free statement and connection resources.
   $stmt = null;
   $conn = null;

 

case-sensitive in where clause

$
0
0

Hello,

I need a case-sensitive where clause:

and typ= 'A' collate german_phonebook_cs_as

How can I realize this? The posted code doesn't work.

Thanks for your help.



Native Client 11 or ODBC Driver 11 for SQL Server?

$
0
0

Should our clients be connecting to our SQL Servers using "SQL Server Native Client 11.0" or "ODBC Driver 11 for SQL Server"

Thanks

How to divide a column into two by using self join??

$
0
0

I was trying to do a query using the AdventureWorks2012 ,in which the managers and the employees who work under those managers will be separated into two columns.

USE AdventureWorks2012

SELECT

             m.JobTitle AS [Manager],e.JobTitle AS [Employees]

FROM

             HumanResources.Employee AS m INNER JOIN HumanResources.Employee AS e
ON      

            m.BusinessEntityID=e.BusinessEntityID

WHERE

              m.JobTitle LIKE'%Manager' AND m.JobTitle ='Chief Executive Officer'  AND (e.JobTitle NOT LIKE '%Manager' AND m.JobTitle <> 'Chief Executive Officer')


Like, the chief executive officer or the ceo is the head of the so all the employees should first come into the employees column under his suppervision. Then, the Account manager And then all the employees who work under him and so on.

I tried the same query with cross join as well as case expression too. But none of them helped.I hope that you will understand mu question.

So,plzz help.

 


Retrieving with PHP pdf stored in binary field varbinary

$
0
0

Hi all,

I'm discovering ms sql server with php development, I'm at the beginner level !

I saw a lot of sites, forums, questions but I haven't found my answer or it doesn't work ! Maybe I do wrong or ignore a big point.

I'm trying to retrieve a pdf file stored in a binary field (configured as varbinary(max)) from my database without any orm layer or other mess ! Only freetds and mssql_* functions.

I got a connection, trigger a query and retrieve the results, no problem.
And then, impossible to restore my data in a good way to set the content of my http'response.

Is it possible or not to deal like this to display a pdf file stored in database ? Or am I compelled to get it by a procedure and let sql server do the job ?
To me, we should succeed by the php way.. (And it seems a lot of people succeed in it, except me !)

Some of my code to get this behavior :

// connection and retrieve
$sql_select = sprintf('select docstring from docstring');

$connexion = mssql_connect('server', 'username', 'password');

if (!$connexion || !mssql_select_db('database', $connexion))
{
  die('Not connected');
}

$version = mssql_query($sql_select);
$row = mssql_fetch_array($version);

// [ $row is an 1-element array containing my binary data at $row[0] ]

// some try to display it in my browser
// 1.
header ('Content-type: application/pdf');
print ($row[0]);

// 2.
header ('Content-type: application/pdf');
$unpacked = unpack('H*hex', $row[0]);
print ($packed['hex']);

// 3.
header ('Content-type: application/pdf');
echo mssql_result($version, 0, 0);

4.
build a file and send it to the browser : doesn't work too and I found it a little dirty cause if we can build a pdf file from these data, we can display it on a brower, in my mind...

I always get a display error in browser or in a pdf reader saying the file must be corrupted or wrong decoded...

About my environment :
sql server : 10.50.1600 : SQL Server 2008 R2 RTM
php 5.3
freetds tds version : 4.2 (also tested with 7.0)
example of what I see in my binary data from mssql management studio: 0x255044462D312E350D25E2E3CFD30D0A3136312030206F626A0D3C3C2F4C696E656172697A656420312F4C2[...] 

Have you ever met this kind of issue ? I've seen a lot of posts but never resolve mine.. And i'm a little desperate !

Thanks for reading !

Big thanks for answering !

Login fails when trying to connect to sql server

$
0
0

I have server that runs windows 2003 that has my web app on it. I have another server which has SQL Server Management Studio and has my database on it. 

I am having a problem connecting to the database. I had to go through a lot of trial and error to get to where I am now. I am not going to list all the things I did unless someone requests because I don't know if it is relevant to my error or not. 

But I am trying to connect to my database through PHP but keep getting the following error. 

Array
(
[0] => Array
(
[0] => 28000
[SQLSTATE] => 28000
[1] => 18456
[code] => 18456
[2] => [Microsoft][SQL Server Native Client 10.0][SQL Server]Login failed for user 'admin'.
[message] => [Microsoft][SQL Server Native Client 10.0][SQL Server]Login failed for user 'admin'.
)
[1] => Array
(
[0] => 42000
[SQLSTATE] => 42000
[1] => 4060
[code] => 4060
[2] => [Microsoft][SQL Server Native Client 10.0][SQL Server]Cannot open database "Mydb" requested by the login. The login failed.
[message] => [Microsoft][SQL Server Native Client 10.0][SQL Server]Cannot open database "Mydb" requested by the login. The login failed.
)
[2] => Array
(
[0] => 28000
[SQLSTATE] => 28000
[1] => 18456
[code] => 18456
[2] => [Microsoft][SQL Server Native Client 10.0][SQL Server]Login failed for user 'admin'.
[message] => [Microsoft][SQL Server Native Client 10.0][SQL Server]Login failed for user 'admin'.
)
[3] => Array
(
[0] => 42000
[SQLSTATE] => 42000
[1] => 4060
[code] => 4060
[2] => [Microsoft][SQL Server Native Client 10.0][SQL Server]Cannot open database "Mydb" requested by the login. The login failed.
[message] => [Microsoft][SQL Server Native Client 10.0][SQL Server]Cannot open database "Mydb" requested by the login. The login failed.
)
)

I believe the server name is right, which is the IP address. It doesn't try and login in and says it cannot find the named pipe(or something like that) if i change the IP to something else.

The credentials are fine as I use the same thing to log in to SQL server management studio.

If I change the username to something random it says the login failed but doesn't return the database name and there is less info returned. So I believe it recognizing the user name.

I checked my password multiple times to make sure there wasn't a typo or anything.

The connection settings are set for windows and sql server authentication.


MS SQL Server 2000 ODBC drivers for Red Hat Linux 6.3 (64 bit)

$
0
0

Hi

I am trying to establish connectivity from Red Hat Linux 6.3 64 bit server to the MS-SQL server 2000 which is installed on Microsoft Windows Server 2003.

I have enabled the necessary firewalls between both the servers.

However, i am unable to find the right sql server odbc driver that i can use to install on the linux  platform.

Request you to please do the needful.

Regards

Sharath

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

windows 10 upgrade

$
0
0

After upgrade of Windows 8.1 to 10 this message appeared: 

sqlmangr.exe - Ordinal Not Found

The ordinal 1 could not be located in the dynamic link library

C:\WINDOWS\SYSTEM32\SQLUNIRL.dll

Compile 64-bit SQL Server Driver for PHP - php_sqlsrv.dll

$
0
0

Follow the instructions from  README.TXT of the source code, (http://sqlsrvphp.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=31762)
I can compile 32-bit php_sqlsrv.dll in Visual Studio 2008 easily. But got some errors when I try to create x64 php_sqlsrv.dll.
I can compile x64 PHP 5.3.1 from source code with php_curl, php_zip etc .  without any problem.
when compiling 32-bit php_sqlsrv.dll, in config.w32 ,  need to  remove this line
ADD_FLAG( 'CFLAGS_SQLSRV', '/WX' );  
/WX  flag is not necessary,  makes some trouble.
My machine configuration:
MS Windows 7 64-bit
MS Visual Studio 2008 Professional

If someone has a successful story in x64, Please give me a post.
thanks a lot.
 

Anyone compiled on PHP 7?

$
0
0

I was wondering if anyone has tried and managed to compile sqlsrv extension for PHP 7?

I have been trying, but haven't managed yet.

Viewing all 163 articles
Browse latest View live