CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Still having problems with a special character
Pages: 1 [2]

Author Topic: Still having problems with a special character  (Read 5506 times)

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Still having problems with a special character
April 08, 2009, 08:49:48 am

in my.cnf, add

log             = /var/log/mysql.log

in the mysqld section

you will need to then restart mysql

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

Michał Mach

  • Ask me questions
  • ****
  • Posts: 748
  • Karma: 59
    • CiviCRM site
  • CiviCRM version: latest
  • CMS version: Drupal and Joomla latest
  • MySQL version: numerous
  • PHP version: 5.3 and 5.2
Re: Still having problems with a special character
April 08, 2009, 09:11:20 am
Hey,

Quote from: Erik Hommel on April 08, 2009, 07:09:06 am
From my previous post I would imagine I change the character set for the database and the server to be utf8 also, is that correct?

No, settings that you have should be enough - I have exactly the same as you and extended characters end up in the database just fine.

Quote from: Erik Hommel on April 08, 2009, 07:09:06 am
And can someone explain to me why this only causes a problem when I go through the API and NOT when I update in CiviCRM itself or directly in the MySQL database?

As Lobo mentioned, there shouldn't be any difference - both ways use practically the same "infrastructure" to initialise DB connection. Would be good to check it though.

Is "é" the only character that you have problems with? Did you try any other extended characters?

Thx,
m
Found this reply helpful? Contribute NOW and help us improve CiviCRM with the Make it Happen! initiative.

My absolute favourite: Wordpress Integration!.

Donate Now!

Erik Hommel

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1773
  • Karma: 59
    • EE-atWork
  • CiviCRM version: all sorts
  • CMS version: Drupal
  • MySQL version: Ubuntu's latest LTS version
  • PHP version: Ubuntu's latest LTS version
Re: Still having problems with a special character
April 08, 2009, 10:03:58 am
I agree it is a very strange phenomenen.......I will try with other special characters, and switch on the MySQL logging. I will get back to you!
And.....thanks for the support!!!!
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

Erik Hommel

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1773
  • Karma: 59
    • EE-atWork
  • CiviCRM version: all sorts
  • CMS version: Drupal
  • MySQL version: Ubuntu's latest LTS version
  • PHP version: Ubuntu's latest LTS version
Re: Still having problems with a special character
April 08, 2009, 10:05:37 am
As far as other special characters go, I have now tried
Quote
RenëÖó&egrave
and I end up with
Quote
Ren
in CiviCRM..... ???
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

Erik Hommel

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1773
  • Karma: 59
    • EE-atWork
  • CiviCRM version: all sorts
  • CMS version: Drupal
  • MySQL version: Ubuntu's latest LTS version
  • PHP version: Ubuntu's latest LTS version
Re: Still having problems with a special character
April 08, 2009, 10:18:46 am
Lobo, I have changed my.cnf, how do I see the log entries you asked for?
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Still having problems with a special character
April 08, 2009, 03:22:08 pm

the mysql log should be in /var/log/mysql.log (or the path u specified)

is this on a windows machine? maybe the OS is the culprit :)

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

Erik Hommel

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1773
  • Karma: 59
    • EE-atWork
  • CiviCRM version: all sorts
  • CMS version: Drupal
  • MySQL version: Ubuntu's latest LTS version
  • PHP version: Ubuntu's latest LTS version
Re: Still having problems with a special character
April 09, 2009, 12:14:53 am
Hi lobo,
it would be fun if the OS was the culprit wouldn't it?  ;) And on my localhost it is Windows Vista. However, the same problem occurs on our demosite, and that is a Linux box so looks like Microsoft gets out of jail for free.......
In my local case I had also switched on the Multi Language support. Although I can not imagine why that would make any difference, just to be sure...........So I have now reinstalled CiviCRM 2.2.2 on my localhost and will try to run my script in the new setting. So watch this space.....

Erik
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

Erik Hommel

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1773
  • Karma: 59
    • EE-atWork
  • CiviCRM version: all sorts
  • CMS version: Drupal
  • MySQL version: Ubuntu's latest LTS version
  • PHP version: Ubuntu's latest LTS version
Re: Still having problems with a special character
January 15, 2010, 05:07:24 am
I have in the meantime done another conversion. I have made sure that all MySQL schemas, databases and fields have utf8 and unicode. But I still have the same problem, even when using a Linux machine. For this particular conversion I have worked around the problem by using the following function after a contact, location or note has been added of the type Organisation:
Code: [Select]
private function correct_specials($field) {

/* this function checks if there are special characters
   in name or address fields, and updates the fields
   directly in the Civi database.  */
global $db_civi;
$name = NULL;
$digit = 0;
$specials = array("ë", "í","á", "é","ü", "ú", "ñ","ä","ö", "ó", "ï");
$update = FALSE;

switch($field){

case "name":

/* check organisation */
foreach ($specials as $special ){
$digit = strpos($this->name, $special);

if (is_integer($digit)) {
$update = TRUE;
}
}
/* if special chars found */
if ($update) {
$name = $db_civi->real_escape_string($this->name);

$upd_name = "UPDATE civicrm_contact SET sort_name =
'$name', display_name = '$name', organization_name =
'$name' WHERE id = $this->id";
$r_name = $db_civi->query($upd_name) or die("Can't
execute SQL-query " .$upd_name ." (Class Organisation,
function correct_specials), error: " .
$db_civi->errno. ", " . $db_civi->error);

}
break;

case "address":

/* check address1 */
foreach ($specials as $special ){
$digit = strpos($this->address1, $special);

if (is_integer($digit)) {
$update = TRUE;
}
}
/* check city1 if still required */
if (!$update) {
foreach ($specials as $special ){
$digit = strpos($this->city1, $special);

if (is_integer($digit)) {
$update = TRUE;
}
}
}

/* if special chars found */
if ($update) {

$street = $db_civi->real_escape_string($this->address1);
$city = $db_civi->real_escape_string($this->city1);

$upd_adr = "UPDATE civicrm_address SET street_address =
'$street', city = '$city' WHERE contact_id =
$this->id";
$r_adr = $db_civi->query($upd_adr) or die("Can't
execute SQL-query " .$upd_adr ." (Class Organisation,
function correct_specials), error: " .
$db_civi->errno. ", " . $db_civi->error);

}
break;

case "note":

/* check note */
foreach ($specials as $special ){
$digit = strpos($this->note5, $special);

if (is_integer($digit)) {
$update = TRUE;
}
}

/* if special chars found */
if ($update) {

$note = $db_civi->real_escape_string($this->note5);

$upd_note = "UPDATE civicrm_note SET note =
'$note' WHERE contact_id = $this->id";
$r_note = $db_civi->query($upd_note) or die("Can't
execute SQL-query " .$upd_note ." (Class Organisation,
function correct_specials), error: " .
$db_civi->errno. ", " . $db_civi->error);

}
break;

} // switch
}


and this when an Individual is added:
Code: [Select]
private function correct_specials($field) {

/* this function checks if there are special characters
   in name or address fields, and updates the fields
   directly in the Civi database. */
global $db_civi;
$first = NULL;
$middle = NULL;
$last = NULL;
$sort = NULL;
$diplay = NULL;
$digit = 0;
$specials = array("ë", "í","á", "é","ü", "ú", "ñ","ä","ö", "ó", "ï");
$update = FALSE;

switch($field){

case "name":

/* check surname */
foreach ($specials as $special ){
$digit = strpos($this->surname, $special);

if (is_integer($digit)) {
$update = TRUE;
}
}
/* check first name if still required */
if (!$update) {
foreach ($specials as $special ){
$digit = strpos($this->firstname, $special);

if (is_integer($digit)) {
$update = TRUE;
}
}
}
/* check middle name if still required */
if (!$update) {
foreach ($specials as $special ){
$digit = strpos($this->middlename, $special);

if (is_integer($digit)) {
$update = TRUE;
}
}
}

/* if special chars found */
if ($update) {
$first = $db_civi->real_escape_string($this->firstname);
$middle = $db_civi->real_escape_string($this->middlename);
$last = $db_civi->real_escape_string($this->surname);
$sort = $last.", ".$first;

if (empty($middle)) {
if (empty($first)) {
$display = $last;
} else {
$display = $first." ".$last;
}
} else {
if (empty($first)) {
$display = $middle." ".$last;
} else {
$display = $first." ".$middle." ".$last;
}
}

$upd_name = "UPDATE civicrm_contact SET first_name =
'$first', last_name = '$last', middle_name =
'$middle', sort_name = '$sort', display_name =
'$display', addressee_display = '$display'
WHERE id = $this->id";
$r_name = $db_civi->query($upd_name) or die("Can't
execute SQL-query " .$upd_name ." (Class Individual,
function correct_specials), error: " .
$db_civi->errno. ", " . $db_civi->error);

}
break;

case "address":

/* check address2 */
foreach ($specials as $special ){
$digit = strpos($this->address2, $special);

if (is_integer($digit)) {
$update = TRUE;
}
}
/* check city2 if still required */
if (!$update) {
foreach ($specials as $special ){
$digit = strpos($this->city2, $special);

if (is_integer($digit)) {
$update = TRUE;
}
}
}

/* if special chars found */
if ($update) {

$street = $db_civi->real_escape_string($this->address2);
$city = $db_civi->real_escape_string($this->city2);

$upd_adr = "UPDATE civicrm_address SET street_address =
'$street', city = '$city' WHERE contact_id =
$this->id";
$r_adr = $db_civi->query($upd_adr) or die("Can't
execute SQL-query " .$upd_adr ." (Class Individual,
function correct_specials), error: " .
$db_civi->errno. ", " . $db_civi->error);

}
break;

case "note":

/* check note */
foreach ($specials as $special ){
$digit = strpos($this->note5, $special);

if (is_integer($digit)) {
$update = TRUE;
}
}

/* if special chars found */
if ($update) {

$note = $db_civi->real_escape_string($this->note5);

$upd_note = "UPDATE civicrm_note SET note =
'$note' WHERE contact_id = $this->id";
$r_note = $db_civi->query($upd_note) or die("Can't
execute SQL-query " .$upd_note ." (Class Individual,
function correct_specials), error: " .
$db_civi->errno. ", " . $db_civi->error);

}
break;

} // switch
}

After completion of this project and doing a blog about it, I will dive into this issue and see if I can work out where the problem is, and if there is a way to solve it in the API.

Erik
Consultant/project manager at EEatWork and CiviCooP (http://www.civicoop.org/)

Pages: 1 [2]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • APIs and Hooks (Moderator: Donald Lobo) »
  • Still having problems with a special character

This forum was archived on 2017-11-26.