{"id":1402,"date":"2013-01-22T17:54:17","date_gmt":"2013-01-22T17:54:17","guid":{"rendered":"http:\/\/www.robertprice.co.uk\/robblog\/?p=1402"},"modified":"2013-01-22T17:54:17","modified_gmt":"2013-01-22T17:54:17","slug":"using-sql-server-ntext-columns-in-php","status":"publish","type":"post","link":"https:\/\/www.robertprice.co.uk\/robblog\/using-sql-server-ntext-columns-in-php\/","title":{"rendered":"Using SQL Server ntext Columns In PHP"},"content":{"rendered":"<p>I had to connect to a SQL Server database from a PHP script earlier, and I came across an error I wasn&#8217;t expecting. <\/p>\n<p>My SQL was working fine, until I tried to select one particular column, it would then give me a 4004 error. Other columns in this table worked fine, so I investigated more.<\/p>\n<p>The error string returned with the 4004 error code was &#8220;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.&#8221;<\/p>\n<p>Looking at the table definition, the column I was trying to SELECT was of type <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms187993.aspx\">ntext<\/a>. This is used to hold UTF-8 data.<\/p>\n<p>By default the driver I had installed for PHP on Ubuntu Linux using<\/p>\n<pre class=\"lang:sh decode:true \" title=\"how to install SQL Server drivers for PHP on Ubuntu Linux\" >apt-get install php5-sybase<\/pre>\n<p>couldn&#8217;t understand this UTF-8 data. The solution is to edit the conf file used by <a href=\"http:\/\/freetds.schemamania.org\/\">freetds<\/a>, which is the code used to talk to the SQL Server database by the <a href=\"http:\/\/php.net\/manual\/en\/ref.pdo-dblib.php\">PDO DBLib<\/a> library.<\/p>\n<p>So, in <code>\/etc\/freedts\/freetds.conf<\/code> I added these settings<\/p>\n<pre class=\"lang:default decode:true \" title=\"freetds settings for accessing ntext fields on SQL Server\" >[global]\ntds version = 8.0\nclient charset = UTF-8<\/pre>\n<p>After adding those settings, I was successfully able to <code>SELECT<\/code> the ntext column from the SQL Server database.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I had to connect to a SQL Server database from a PHP script earlier, and I came across an error I wasn&#8217;t expecting. My SQL was working fine, until I tried to select one particular column, it would then give me a 4004 error. Other columns in this table worked fine, so I investigated more. &hellip; <a href=\"https:\/\/www.robertprice.co.uk\/robblog\/using-sql-server-ntext-columns-in-php\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Using SQL Server ntext Columns In PHP&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[2],"tags":[15,50,64,75],"class_list":["post-1402","post","type-post","status-publish","format-standard","hentry","category-dev","tag-databases","tag-php","tag-sqlserver","tag-web-development"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Using SQL Server ntext Columns In PHP - Robert Price<\/title>\n<meta name=\"description\" content=\"How to use ntext columns from MS SQL Server with PHP PDO DBlib. Preventing the dreaded 4004 error.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.robertprice.co.uk\/robblog\/using-sql-server-ntext-columns-in-php\/\" \/>\n<meta property=\"og:locale\" content=\"en_GB\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Using SQL Server ntext Columns In PHP - Robert Price\" \/>\n<meta property=\"og:description\" content=\"How to use ntext columns from MS SQL Server with PHP PDO DBlib. Preventing the dreaded 4004 error.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.robertprice.co.uk\/robblog\/using-sql-server-ntext-columns-in-php\/\" \/>\n<meta property=\"og:site_name\" content=\"Robert Price\" \/>\n<meta property=\"article:published_time\" content=\"2013-01-22T17:54:17+00:00\" \/>\n<meta name=\"author\" content=\"rob\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"rob\" \/>\n\t<meta name=\"twitter:label2\" content=\"Estimated reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/using-sql-server-ntext-columns-in-php\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/using-sql-server-ntext-columns-in-php\\\/\"},\"author\":{\"name\":\"rob\",\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/#\\\/schema\\\/person\\\/fac6d5b076e0e14e1fb13e15b542a6c5\"},\"headline\":\"Using SQL Server ntext Columns In PHP\",\"datePublished\":\"2013-01-22T17:54:17+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/using-sql-server-ntext-columns-in-php\\\/\"},\"wordCount\":188,\"keywords\":[\"databases\",\"PHP\",\"sqlserver\",\"Web Development\"],\"articleSection\":[\"Dev\"],\"inLanguage\":\"en-GB\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/using-sql-server-ntext-columns-in-php\\\/\",\"url\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/using-sql-server-ntext-columns-in-php\\\/\",\"name\":\"Using SQL Server ntext Columns In PHP - Robert Price\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/#website\"},\"datePublished\":\"2013-01-22T17:54:17+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/#\\\/schema\\\/person\\\/fac6d5b076e0e14e1fb13e15b542a6c5\"},\"description\":\"How to use ntext columns from MS SQL Server with PHP PDO DBlib. Preventing the dreaded 4004 error.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/using-sql-server-ntext-columns-in-php\\\/#breadcrumb\"},\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/using-sql-server-ntext-columns-in-php\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/using-sql-server-ntext-columns-in-php\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Using SQL Server ntext Columns In PHP\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/#website\",\"url\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/\",\"name\":\"Robert Price\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-GB\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.robertprice.co.uk\\\/robblog\\\/#\\\/schema\\\/person\\\/fac6d5b076e0e14e1fb13e15b542a6c5\",\"name\":\"rob\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/6f0eb511179100a4e968abc70403e33686e6ab3e992e392bedd2ccac01da666c?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/6f0eb511179100a4e968abc70403e33686e6ab3e992e392bedd2ccac01da666c?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/6f0eb511179100a4e968abc70403e33686e6ab3e992e392bedd2ccac01da666c?s=96&d=mm&r=g\",\"caption\":\"rob\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Using SQL Server ntext Columns In PHP - Robert Price","description":"How to use ntext columns from MS SQL Server with PHP PDO DBlib. Preventing the dreaded 4004 error.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.robertprice.co.uk\/robblog\/using-sql-server-ntext-columns-in-php\/","og_locale":"en_GB","og_type":"article","og_title":"Using SQL Server ntext Columns In PHP - Robert Price","og_description":"How to use ntext columns from MS SQL Server with PHP PDO DBlib. Preventing the dreaded 4004 error.","og_url":"https:\/\/www.robertprice.co.uk\/robblog\/using-sql-server-ntext-columns-in-php\/","og_site_name":"Robert Price","article_published_time":"2013-01-22T17:54:17+00:00","author":"rob","twitter_card":"summary_large_image","twitter_misc":{"Written by":"rob","Estimated reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.robertprice.co.uk\/robblog\/using-sql-server-ntext-columns-in-php\/#article","isPartOf":{"@id":"https:\/\/www.robertprice.co.uk\/robblog\/using-sql-server-ntext-columns-in-php\/"},"author":{"name":"rob","@id":"https:\/\/www.robertprice.co.uk\/robblog\/#\/schema\/person\/fac6d5b076e0e14e1fb13e15b542a6c5"},"headline":"Using SQL Server ntext Columns In PHP","datePublished":"2013-01-22T17:54:17+00:00","mainEntityOfPage":{"@id":"https:\/\/www.robertprice.co.uk\/robblog\/using-sql-server-ntext-columns-in-php\/"},"wordCount":188,"keywords":["databases","PHP","sqlserver","Web Development"],"articleSection":["Dev"],"inLanguage":"en-GB"},{"@type":"WebPage","@id":"https:\/\/www.robertprice.co.uk\/robblog\/using-sql-server-ntext-columns-in-php\/","url":"https:\/\/www.robertprice.co.uk\/robblog\/using-sql-server-ntext-columns-in-php\/","name":"Using SQL Server ntext Columns In PHP - Robert Price","isPartOf":{"@id":"https:\/\/www.robertprice.co.uk\/robblog\/#website"},"datePublished":"2013-01-22T17:54:17+00:00","author":{"@id":"https:\/\/www.robertprice.co.uk\/robblog\/#\/schema\/person\/fac6d5b076e0e14e1fb13e15b542a6c5"},"description":"How to use ntext columns from MS SQL Server with PHP PDO DBlib. Preventing the dreaded 4004 error.","breadcrumb":{"@id":"https:\/\/www.robertprice.co.uk\/robblog\/using-sql-server-ntext-columns-in-php\/#breadcrumb"},"inLanguage":"en-GB","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.robertprice.co.uk\/robblog\/using-sql-server-ntext-columns-in-php\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.robertprice.co.uk\/robblog\/using-sql-server-ntext-columns-in-php\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.robertprice.co.uk\/robblog\/"},{"@type":"ListItem","position":2,"name":"Using SQL Server ntext Columns In PHP"}]},{"@type":"WebSite","@id":"https:\/\/www.robertprice.co.uk\/robblog\/#website","url":"https:\/\/www.robertprice.co.uk\/robblog\/","name":"Robert Price","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.robertprice.co.uk\/robblog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-GB"},{"@type":"Person","@id":"https:\/\/www.robertprice.co.uk\/robblog\/#\/schema\/person\/fac6d5b076e0e14e1fb13e15b542a6c5","name":"rob","image":{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/secure.gravatar.com\/avatar\/6f0eb511179100a4e968abc70403e33686e6ab3e992e392bedd2ccac01da666c?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/6f0eb511179100a4e968abc70403e33686e6ab3e992e392bedd2ccac01da666c?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/6f0eb511179100a4e968abc70403e33686e6ab3e992e392bedd2ccac01da666c?s=96&d=mm&r=g","caption":"rob"}}]}},"_links":{"self":[{"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/posts\/1402","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/comments?post=1402"}],"version-history":[{"count":0,"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/posts\/1402\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/media?parent=1402"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/categories?post=1402"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.robertprice.co.uk\/robblog\/wp-json\/wp\/v2\/tags?post=1402"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}