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 (Moderator: Donald Lobo) »
  • db_query (UPDATE) => no changes in the database
Pages: [1]

Author Topic: db_query (UPDATE) => no changes in the database  (Read 3792 times)

alextronic

  • I post occasionally
  • **
  • Posts: 57
  • Karma: 2
  • I do what I do
db_query (UPDATE) => no changes in the database
September 08, 2009, 03:57:41 pm
I have a custom column in the civicrm_contribution_page table, don't know if that's bad practice but that's where we are because of other people, so please bear with me. I try to update one value in this column, but...

Code: [Select]
db_query("UPDATE civicrm_database.civicrm_contribution_page SET custom_column='%s' WHERE id=%d", $string, $node->nid );
...doesn't work. This code, BTW, is inside a content type template. I have tried converting the table to InnoDB via phpmyadmin.

The column custom_column is VARCHAR 128, not null, etc, though I've tried many other combinations... is there a standard for manipulating data types / tables that I'm not aware of? Might the table be locked in some way?... ouch.

Thanks in advance.

alextronic

  • I post occasionally
  • **
  • Posts: 57
  • Karma: 2
  • I do what I do
Re: db_query (UPDATE) => no changes in the database
September 08, 2009, 04:35:24 pm
OK, I know this thread is bizarre, and much more if I add that I also need to modify a custom column's field in drupal's table node.

Code: [Select]
db_query("UPDATE drupal_database.node SET custom_column='%s' WHERE nid=%d", $string, $node->nid );
...which also doesn't work.

BUT,

the following updates DO work:

Code: [Select]
db_query("UPDATE civicrm_database.civicrm_contribution_page SET project_type = '%s' WHERE id = %d", $node->field_projecttype[0]['safe'], $node->field_id_contribpage[0]['value'] );

db_query("UPDATE civicrm_database.civicrm_contribution_page SET project_type_2 = '%s' WHERE id = %d", $node->field_projecttype[1]['safe'], $node->field_id_contribpage[0]['value'] );

db_query("UPDATE civicrm_database.civicrm_contribution_page SET project_type_3 = '%s' WHERE id = %d", $node->field_projecttype[2]['safe'], $node->field_id_contribpage[0]['value'] );

db_query("UPDATE civicrm_database.civicrm_contribution_page SET country = '%s' WHERE id = %d", countries_api_get_name($location['country']), $node->field_id_contribpage[0]['value'] );

db_query("UPDATE civicrm_database.civicrm_contribution_page SET region = '%s' WHERE id = %d", $node->field_region[0]['value'], $node->field_id_contribpage[0]['value'] );

db_query("UPDATE civicrm_database.civicrm_contribution_page SET contribution_name = '%s' WHERE id = %d", $node->title, $node->field_id_contribpage[0]['value'] );

I repeat; I know this is NOT best practice. But I really need to know (learn).

Thank you again.

Alex
« Last Edit: September 08, 2009, 05:22:12 pm by alextronic »

alextronic

  • I post occasionally
  • **
  • Posts: 57
  • Karma: 2
  • I do what I do
Re: db_query (UPDATE) => no changes in the database
September 09, 2009, 05:48:39 am
I think there must be a way to do these db updates that does work; and I'm sure that it can't be that hard. I think my syntax is OK, maybe it's a problem of Drupal or CiviCRM standards when it comes to updating the databases directly. Or maybe those tables (civicrm_contribution_page and node) are locked or protected in a way by default --I don't think so--, or perhaps there is a way to create custom columns/fields in those tables so that the data type ant attributes is compatible with the strings provided in the query... I really don't know. Maybe the problem is having db_queries in a content template? Anyone?...

Thank you
Alex

alextronic

  • I post occasionally
  • **
  • Posts: 57
  • Karma: 2
  • I do what I do
Re: db_query (UPDATE) => no changes in the database
September 10, 2009, 05:53:44 pm
The problem was to UPDATE the database from a content template, nothing to do with CiviCRM. I have moved the db_query instructions to a node and they are executed without a problem.
Sorry, I guess I imagined CiviCRM tables had a kind of lock.
« Last Edit: September 14, 2009, 12:18:36 pm by alextronic »

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • db_query (UPDATE) => no changes in the database

This forum was archived on 2017-11-26.