Tag: php

PDO equivalent of mysql_num_rows or mssql_num_rows

I know this question has been asked before but it seems like the solutions have been specific to the problem presented. I have a codebase with hundreds of instances where mssql_num_rows is used. Code example: $db->execute($sql); if ($db->getRowsAffected() > 0) { $total = $db->fetch(); In db class: $this->rowsaffected = mssql_num_rows($this->query_result); I can’t create generic SELECT […]

'PDOException' with message 'SQLSTATE: String data, right truncated: 0

NOTE: I have narrowed this problem down to specifically PDO because I am able to successfully prepare and execute statements using the odbc_* functions. Why can’t I bind this parameter to the PDO prepared statement? This works: $mssqldriver = ‘ODBC Driver 13 for SQL Server’; $pdoDB = new PDO(“odbc:Driver=$mssqldriver;Server=$hostname;Database=$dbname”, $username, $password); $pdoDB->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); […]

PDO MSSQL Server – Driver not found

I am currently trying to connect to my localdb on MSSQL 2012 Express. I have downloaded and installed the official microsoft driver from http://www.microsoft.com/en-us/download/details.aspx?id=20098 I get some kind of SQLSRV section in my phpinfo(). But when I try to create a new PDO object it says it does not have the driver. Which I could […]

Connection between MSSQL and PHP 5.3.5 on IIS is not working

I recently installed IIS, PHP 5.3.5 and MySQL, and had it all working. I then has a requirement for MS SQL as well, and what I thought would be an easy task, is now driving me crazy and I can’t figure out how to make it work. According to php_info() the MS SQL drivers aren’t […]

CodeIgniter MSSQL connection

I’m working on a web project that is to be deployed on a 64bit Windows 2008 Server machine running IIS 7.5 and PHP 5.3.8. The database on the system is Microsoft SQL Server 2008 R2. I’m developing the application on the CodeIgniter 2.1.0 framework, and I’m a bit stumped on getting it to connect to […]

SQL Server error 1934 occurs on INSERT to table with computed column PHP/PDO

After adding a computed column to a table in SQL Server 2005 I am getting the following message on INSERT, only via PHP (using PDO) it’s working fine in SQL Server Managment Studio. To ensure I had everything correct I setup a trace with SQL Server Profiler and copy/pasted the INSERT statement into SQL Server […]

Getting data with UTF-8 charset from MSSQL server using PHP FreeTDS extension

I can’t seem to get data from MSSQL encoded as UTF-8 using FreeTDS extension. Connecting: ini_set(‘mssql.charset’, ‘UTF-8’); $this->_resource = mssql_connect($config[‘servername’], $config[‘username’], $config[‘password’]); I have no ability to use any other extension. I’ve tried creating ~/.freetds.conf [global] client charset = UTF-8 I’ve tried passing parameters to php: php -d mssql.charset=”UTF-8″ index.php Data is still not in […]

“Adaptive Server is unavailable or does not exist” error connecting to SQL Server from PHP

I’m attempting to connect to a SQL Server 2005 DB from my Mac using unixODBC and FreeTDS as I have outlined here. However, when I try to connect in to a different DB using the same setup, I get: Connection Failed:[FreeTDS][SQL Server]Unable to connect: Adaptive Server is unavailable or does not exist. Here is my […]

How can I connect to Sql Server from a Mac with PHP PDO?

If you search Google for this question, you will find a lot of incorrect, misleading, and outdated information. Surprisingly, there isn’t a solid answer on Stack Overflow, so we should change that. I am using the Mac port installation of Apache and PHP. I have installed php5-mssql, and I can see mssql on my phpinfo() […]

PHP + SQL Server – How to set charset for connection?

I’m trying to store some data in a SQL Server database through php. Problem is that special chars aren’t converted properly. My app’s charset is iso-8859-1 and the one used by the server is windows-1252. Converting the data manually before inserting doesn’t help, there seems to be some conversion going on. Running the SQL query […]

MS SQL Server is a Microsoft SQL Database product, include sql server standard, sql server management studio, sql server express and so on.