PHP – mssql_query() Error

Background Knowledge


I’m running PHP v5.2.9-2 with SQL Server 2005 Express on Windows Server 2003 R2 SP2.

Error Message


Warning: mssql_query() [function.mssql-query]: message: Unicode data in a Unicode-only collation or ntext data cannot be sent to clients using DB-Library (such as ISQL) or ODBC version 3.7 or earlier. (severity 16)

Solution


Specify the database columns within your database query (select filed1, field2 from foo). Avoid doing queries with the wildcard (*), select * from foo.

Source: PHP Manual on MSSQL_Query()

Example of a Basic MSSQL Query using PHP

An example of a basic MSSQL (Microsoft SQL Server/SQL Server Express) query using PHP.

1
2
3
4
5
6
7
8
9
$szQry = "SELECT column1, column2 FROM foo";
$szDBConn = mssql_connect("host","username","password");
mssql_select_db("database_name", $szDBConn);
$saResults = mssql_query($szQry, $szDBConn);
while($obResults = mssql_fetch_row($saResults))
{
   echo $obResults[0]." ".$obResults[1];
}
mssql_close($szDBConn);

Comments/description of Example

Line #1
SQL statement that will be sent to the MySQL database server.
Line #2
MSSQL database login credentilas; host (127.0.0.1), username and password.
The “host” is the server name or IP address of your database server. If your host has multiple instances the “host” value would be formatted like so “foo\bar”. If your using SQL Server Express the “host” name locally would be “.\SQLEXPRESS”.
Line #3
Select database using the login credentials provided above.
Line #4
Send SQL statement to database.
Line #5-8
Fetch results returned back from the SQL statement. I use a while loop to enumerate through each row of results returned. If you know only one row is going to be retunred the while loop is not necessary.
Line #9
Close database connection.

PHP – Upgrading v5.2.5 to v5.2.8

Background Knowledge


The following is the process I took to upgrade a web server with PHP v5.2.5 to PHP v5.2.8 running on OpenBSD. PEAR is already installed on this system and up to date. I wasn’t sure if I should exclude PEAR at install or not so therefore did not tell the configurator to exclude PEAR at install.

Installation Process


  1. Download the latest stable PHP release from command prompt # wget http://ca.php.net/get/php-5.2.8.tar.gz/from/a/mirror
  2. # tar -zxvf php-5.2.8.tar.gz
  3. ./configure –with-mysql=/usr/local –with-mssql=/usr/local –with-apxs –with-zlib-dir=/usr/lib –with-config-file-path=/var/www/conf –with-iconv=/usr/local/bin/iconv –enable-exif –enable-mbstring –enable-calendar
  4. # make
  5. # make test
  6. # make install
  7. # make clean

As far as I could tell in the PHP 5 ChangeLog since at least PHP v5.2.5 there has not be any changes made to the php.ini configuration file. Therefore I chose to leave the PHP configuration file (php.ini) that was being used with PHP v5.2.5 for PHP v5.2.8.

Issues


  1. At configure I received the following message “checking for a sed that does not truncate output… (cached) /usr/bin/sed
    expr: syntax error ./configure[2322]: test: 0: unexpected operator/operand expr: syntax error ./configure[2337]: test: 0: unexpected operator/operand”

I’m not sure what to make of this error message. I tried to search on Google but was not successful finding any answers. I tested my PHP installation and all appears to be okay. If anyone knows what exactly this error means and how to resolve it please let me know.

MySQL – Can You Concatenate Strings From a Column Into a Single Row?

How would one concatenate strings from a column (multiple rows) into a single row using MySQL? I see its possible with MS SQL Server 2005 and above. Any incite into how to achieve this in MySQL would be much appreciated.

MS SQL Server 2005 – Example


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
SELECT Web_Account_ID,
GroupNameConcat = REPLACE(
	(
	SELECT
		Web_Account_Group_Name_ID AS [DATA()]
	FROM
		tblWebAccountGroup WAG
	WHERE
		WAG.Web_Account_ID = WA.Web_Account_ID
	ORDER BY
		Web_Account_Group_Name_ID
            FOR XML PATH ('')
        ), ' ', ',')
FROM tblWebAccounts WA
ORDER BY Web_Account_ID

Query Results Example


MS SQL Server 2005 query example

Source: aspfaq.com – How do I concatenate strings from a column into a single row?

C#.Net – Parse Error Could Not Load Type

Background Knowledge


My web application ran fine locally but then experienced the “Prase Error Could Not Load Type” error message when I copied the files to the web server. In my case I was producing a web application using Visual Studio 2005 and coding in C#.NET.

Example of Error Message


Server Error in ‘/CustomErrorPages’ Application.


Parser Error

Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.

Parser Error Message: Could not load type ‘CustomErrorPages.WebForm1′.

Source Error:

Line 1: < %@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="CustomErrorPages.WebForm1" %>
Line 2:
Line 3: < !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

Source File: /CustomErrorPages/WebForm1.aspx Line: 1

Solutions


  • Make sure you compiled your project.
  • Make sure your bin folder is in the correct location with the DLL, in this example case “/bin/WebForm1.dll”.
  • Make sure that you created a virtual directory or application root for your project.
  • Make sure you have the correct .NET Framework set in IIS that is required for the application.
  • Make sure you copied all the required application files.