EllisLab text mark
Advanced Search
1 of 2
1
   
Special character insert into mssql
Posted: 16 November 2012 09:35 AM   [ Ignore ]
Joined: 2012-11-08
19 posts

Hello,

the problem I am facing is that when I insert special characters into mssql server I get

name 1.5 # 4 1 ; , ie 

istead of name (1.5), ie

What do I need to change to get normal values?

sorry for spaces

 
Posted: 16 November 2012 09:44 AM   [ Ignore ]   [ # 1 ]   [ Rating: 0 ]
Avatar
Joined: 2011-06-12
21 posts
Juzt1s - 16 November 2012 09:35 AM

Hello,

the problem I am facing is that when I insert special characters into mssql server I get name (1.5), ie istead of name (1.5), ie

What do I need to change to get normal values?

try to quote your post and i get (1.5 & # 4 1 ; not (1.5)
what encode you use on mssql ?

 
Posted: 16 November 2012 09:58 AM   [ Ignore ]   [ # 2 ]   [ Rating: 0 ]
Joined: 2012-11-08
19 posts

I am using:
$db[‘default’][‘char_set’] = ‘utf8’;
$db[‘default’][‘dbcollat’] = ‘utf8_general_ci’;

 
Posted: 16 November 2012 10:01 AM   [ Ignore ]   [ # 3 ]   [ Rating: 0 ]
Avatar
Joined: 2011-06-12
21 posts
Juzt1s - 16 November 2012 09:58 AM

I am using:
$db[‘default’][‘char_set’] = ‘utf8’;
$db[‘default’][‘dbcollat’] = ‘utf8_general_ci’;

it’s mssql right not mysql
mssql use utf16
so
$db[‘default’][‘char_set’] = ‘utf16’;
$db[‘default’][‘dbcollat’] = ‘utf16_general_ci’;

is that work ?

 
Posted: 16 November 2012 10:15 AM   [ Ignore ]   [ # 4 ]   [ Rating: 0 ]
Joined: 2012-11-08
19 posts

It does not. Still a mess in databse column.

EDIT: I’ve check my dtabase collation, it’s - SQL_Latin1_General_CP1_CI_AS

 
Posted: 16 November 2012 10:58 AM   [ Ignore ]   [ # 5 ]   [ Rating: 0 ]
Avatar
Joined: 2011-06-12
21 posts
Juzt1s - 16 November 2012 10:15 AM

It does not. Still a mess in databse column.

EDIT: I’ve check my dtabase collation, it’s - SQL_Latin1_General_CP1_CI_AS

it’s Latin1 try this
$db[‘default’][‘char_set’] = ‘latin1’;
$db[‘default’][‘dbcollat’] = ‘latin1_general_ci’;

 
Posted: 16 November 2012 11:20 AM   [ Ignore ]   [ # 6 ]   [ Rating: 0 ]
Joined: 2012-11-08
19 posts

Does not work.

 
Posted: 19 November 2012 04:51 AM   [ Ignore ]   [ # 7 ]   [ Rating: 0 ]
Joined: 2012-11-08
19 posts

Here is updated and more clear explanation:

The problem I am having is that when I get data out of database everything is fine, but when I write data with special symbols to database I get special symbols coded.

ex. When I write name (1.5), ie I get the name ( 1.5 & # 4 1 ; , ie (without spaces). But when I get from database base everything is fine and name (1.5), ie is shown.

The problem is that my search with special symbols does not work.

here are the configurations. database.config:

$active_group 'default';
$active_record TRUE;

$db['default']['hostname''xx.xx.x.xxx';
$db['default']['username''sa';
$db['default']['password''password';
$db['default']['database''database';
$db['default']['dbdriver''mssql';
$db['default']['dbprefix''';
$db['default']['pconnect'TRUE;
$db['default']['db_debug'FALSE;
$db['default']['cache_on'FALSE;
$db['default']['cachedir''';
$db['default']['char_set''latin1';
$db['default']['dbcollat''latin1_general_ci';
$db['default']['swap_pre''';
$db['default']['autoinit'TRUE;
$db['default']['stricton'FALSE

as you’ve noticed my database collation is SQL_Latin1_General_CP1_CI_AS.

I’ve tried setting values to:

$db[‘default’][‘char_set’] ‘utf8’;
$db[‘default’][‘dbcollat’] ‘utf8_general_ci’

and:

$db[‘default’][‘char_set’] ‘utf16’;
$db[‘default’][‘dbcollat’] ‘utf16_general_ci’

Any ideas how to write data with special symbols or have my search working. The search is simple, I get string, put it in SQL LIKE statement and return the values.

 
Posted: 19 November 2012 05:20 AM   [ Ignore ]   [ # 8 ]   [ Rating: 0 ]
Avatar
Joined: 2012-01-09
117 posts

I suppose you’ve already read the answer to that question on StackOverflow, but here it is again:

@ini_set('mssql.charset''utf-8'); 
 
Posted: 19 November 2012 06:13 AM   [ Ignore ]   [ # 9 ]   [ Rating: 0 ]
Joined: 2012-11-08
19 posts

I did. It works, but when it comes to () the stored value is & # 40; & # 41;

 
Posted: 19 November 2012 06:40 AM   [ Ignore ]   [ # 10 ]   [ Rating: 0 ]
Avatar
Joined: 2012-01-09
117 posts

I assume those values come from user input (e.g. POST data) and as a security measure CodeIgniter translates a few special characters that are found in GET, POST and COOKIE data. This isn’t related to character sets.

 
Posted: 19 November 2012 06:47 AM   [ Ignore ]   [ # 11 ]   [ Rating: 0 ]
Joined: 2012-11-08
19 posts

How do I remove that kind of security?

And yes, it comes from user input. I’ve change a line in config.php to allow specialcharacters.

 
Posted: 19 November 2012 06:59 AM   [ Ignore ]   [ # 12 ]   [ Rating: 0 ]
Avatar
Joined: 2012-01-09
117 posts

This is hard-coded, you can’t affect it by changing a configuration setting. Just decode those characters before inserting them into the database.

 
Posted: 19 November 2012 07:18 AM   [ Ignore ]   [ # 13 ]   [ Rating: 0 ]
Joined: 2012-11-08
19 posts

I’ve tired using : http://www.php.net/manual/en/function.iconv.php

did not help :/

 
Posted: 19 November 2012 07:25 AM   [ Ignore ]   [ # 14 ]   [ Rating: 0 ]
Avatar
Joined: 2012-01-09
117 posts

Again, these are HTML entities, nothing to do with character sets. You need htmlspecialchars_decode().

 
Posted: 19 November 2012 10:22 AM   [ Ignore ]   [ # 15 ]   [ Rating: 0 ]
Joined: 2012-11-08
19 posts

Got it working. Thnx.


Used:

$newname htmlentities($oldname); 

 

 
1 of 2
1