Skip to Content.
Sympa Menu

freetds - Re: [freetds] FreeTDS and PHP: empty strings and NVARCHAR

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: Frediano Ziglio <freddy77 AT gmail.com>
  • To: FreeTDS Development Group <freetds AT lists.ibiblio.org>
  • Subject: Re: [freetds] FreeTDS and PHP: empty strings and NVARCHAR
  • Date: Mon, 11 Jul 2011 14:32:50 +0200

2011/7/11 Mattia <mattia AT p2pforum.it>:
> 2011/7/11 Frediano Ziglio:
>> 2011/7/9 Mattia:
>>> So,
>>> with SYBVARCHAR an empty string is inserted (in presence of strange
>>> characters);
>>> with SYBNVARCHAR, sql server throws an error (unknown data type)
>>> with XSYBNVARCHAR, everything works perfectly.
>>>
>>
>> Could you provide a simple PHP code which demonstrate the problem?
>> Have you the problem inserting data or fetching them? Did you setup
>> correctly client charset?
>>
>
> The problem is inserting data. Fetching them works fine.
> Client charset is UTF-8.
>
> Php code is pretty simple:
>
> <?php
> $conn = mssql_connect($hostname, $db_user, $db_pass ) or die ( "Unable
> to connect" );
> mssql_select_db($db_name) or die("$db_name not found");
>
> $an_id = 1;
> $the_string="This would result    Ő      in an empty string";
>
> $stmt = mssql_init('My_Stored_Proc');
> mssql_bind ($stmt, '@string', $the_string, SQLVARCHAR, false, false);
> mssql_bind($stmt, '@id', $an_id, SQLINT4, false, false);
>
> $result=mssql_execute($stmt) or die('Stored proc execution failed');
> mssql_free_statement($stmt);
> mssql_close($conn);
> ?>
>
> Id gets inserted and mssql_execute returns true. The string is empty.
> Db is a Sql 2008 R2 Web Edition (with the standard edition is the same).
>
> --
> Mattia

Got it!

However I'm pondering if is not better to pass always strings as
unicode. The conversion matrix is the same except for image where
conversion is not possible and binary/varbinary where conversion is
different. But who should pass binary using char data ??

freddy77




Archive powered by MHonArc 2.6.24.

Top of Page