Topics related to the database API implemented by Drupal.

learn more… | top users | synonyms

0
votes
0answers
9 views

db_update query does not work properly

I work with views bulk operations and I wanna change status of selected items in a view. I applied db_update query, but something went wrong. I was debugging my code following: ...
0
votes
0answers
27 views

Save details of form to database table in drupal 7

I'm new to Drupal. I'm fetching ids and title from a database table as key-value pairs and adding them to a drop-down select list. After selecting the respective items in both the lists, I want to ...
1
vote
1answer
45 views

db_update after a submit button is clicked

I want to update a "picture" field with a type of character varying, after a button is click. My customize module is already connected to it's database. This is my form: function ...
1
vote
0answers
14 views

Is db_next_id() thread safe?

My problem: Say, I need to run a massive amount of inserts into two related tables: Table1: id1, data1 Table2: id1 (foreign key), id2, data2. I want my code to work fast, so I can't run a loop like ...
0
votes
1answer
26 views

db_query gives PDO Exception “General error: 1366 Incorrect integer value:” when I try to update table

I'm trying to execute the following SQL query $tweet_id_int = intval($tweet->id); $result = db_query("INSERT INTO tweetsDB (handle,tweet,time_string,tweetid) VALUES ...
0
votes
1answer
17 views

settings and switching to external pgsql db

I am working with Drupal 7.3.4 and attempting to follow the instructions of changing settings.php so that I can switch to a pgsql DB within a module and then switch back to the default mysql after ...
1
vote
1answer
24 views

db_update without table prefix on custom table

I installed Drupal with table prefixes in the database. I have my own tables in the same database which I am trying to update. I am getting an error because Drupal is automatically adding the prefix ...
0
votes
1answer
18 views

how using mysql CAST in db_select

I want to try doing Mysql Casting in my query by db_select but face to error, $q=db_select('node','n'); $q->join('field_data_field_cinema_type', 'fct', 'fct.entity_id = n.nid'); ...
0
votes
0answers
7 views

addExpression() and FROM_UNIXTIME format [duplicate]

Having some trouble figuring this out, all of the examples I have looked at make it appear that what I have done is correct. Here is my query: $query = db_select('webform_submissions', 'w'); ...
1
vote
4answers
92 views

Does node_delete() function deletes the attached media files as well?

I'm deleting my 'articles' created before Sat Nov 1 00:00:00 2014 GMT from Drupal 7.34 site, but I'm not sure whether the node_delete() delete the media files as well? Below is my processing code: ...
0
votes
1answer
9 views

How to drop tables shown as Missing in Schema Report

During development/testing after using Backup and Migrate Restore in conjuction with Schema, Schema will show Extra tables no longer referenced in the database, used by modulesetc, and no longer ...
0
votes
1answer
20 views

Does Drupal cache db_query results for multiple users?

I am running into something strange and perhaps someone here can help me. I am trying to prevent two things from happening at once because the second attempt might be influenced by the first attempt. ...
0
votes
0answers
14 views

Add product using Drupal 7 / Ubercart 3 Api

I'm writting my stupid import module and need to programaticaly add products to db. I need to add title, price and link product to existing group; I'v made some research of ubercart api and found ...
0
votes
0answers
11 views

DUAL table query

How do I construct the following query with DB API (so it's database engine independent): SELECT 1 FROM DUAL This example is for MySQL. I believe the Postgres version is SELECT 1
0
votes
1answer
28 views

SQL replace() function in PDO

I'd like to convert the instructions from this answer into a general script that can be reused across projects. I'm wondering how these commands can be written in Drupal 7 PDO format: UPDATE ...
0
votes
2answers
30 views

Select data from database when submitting a form

I'm trying to learn how to make select queries with Drupal, so I made a form, and when I submit the form I try to query the database and get some results, but instead I'm redirected to an error page, ...
0
votes
1answer
38 views

How do I write this PHP query the Drupal way (database abstraction)?

I am using the code below to evaluate if a panel pane should display. I've read the docs on database abstraction, but I just don't really understand how to apply it. Of course, the dpm values are for ...
0
votes
1answer
31 views

Obtain an image url

I've a module that in the .install creates a table. In that table I have to save the information of one image, that's imagen_leyenda. I obtain that image from a form, that I have created in my ...
0
votes
1answer
65 views

List nodes of children using taxonomy_select_nodes

I want to list nodes from children terms using or editing taxonomy_select_nodes function. Actually I added these few lines but I get an infinite loop or slow response: function ...
0
votes
2answers
28 views

Database object syntax for where conditions giving error

I am trying to convert the following SQL query in calls to the database API. SELECT p.id, p.message,t.posted, p.posted AS reply_date,p.poster_id,t.id,t.subject, t.forum_id FROM punbb.punbb_posts AS p ...
1
vote
1answer
59 views

How to backport db_merge() to drupal 6?

I am converting a module from drupal 7 to drupal 6. I have a query in drupal 7. The query contains function db_merge() db_merge('facebook_rules_user_tokens') ->key(array('uid' => ...
1
vote
0answers
64 views

db-update is not working

Node status does not change. If I set status = 1 it works fine. function yt_common_changes_mark_spam($args) { $num_updated = db_update('node') // Table name no longer needs {} ...
0
votes
1answer
80 views

How to convert a complex select query to Drupal dynamic query?

I read online that db_query is faster than db_select for complex queries. I wanted to check this for one of the queries I have written. Following is the code with db_query: $query = "SELECT ...
1
vote
1answer
215 views

How to do multiple conditions for db_update by using OR condition?

I would like to convert the following UpdateQuery statement to work with multiple conditions by using OR instead of the default AND condition: db_update('system') ->fields(array('status' ...
5
votes
3answers
436 views

Whats faster db_query, db_select, or EntityFieldQuery

So I'm trying to find out what is faster db_query, db_select, or EntityFieldQuery. Currently I'm using EntityFieldQuery. I'm grabbing about 1600 node entries. I realize this can be taxing on the ...
2
votes
1answer
266 views

MySQL date format functions in Drupal

How can I do a MySQL date function in Drupal? I have this now: $select = db_select('someTable', 'st'); $select->addExpression('DATE_FORMAT(FROM_UNIXTIME(created), "%Y-%m")', 'createdMonth'); ...
0
votes
2answers
122 views

Select users with only one role

How can i select all users wich have only 1 role. For example i got 4 users: User 1: Role 1, Role 2 User 2: Role 1 User 3: Role 1, Role 2 User 4: Role 1 How can i retrieve a list of users ...
0
votes
2answers
44 views

How add/update a record conditionally based on existence of primary key?

I have a table with structure: Table ( record_1 int, record_2 int, PRIMARY KEY (record_1) ); I want to write/update a record based on its existence. I was told to use drupal_write_record(), but for ...
0
votes
1answer
44 views

How to translate a database query with a subquery to a db_select statement?

Assume any variable that doesn't have a definition in the sample code is defined elsewhere. I need to get the results of the following query: select type, eid, vid, language, keyword, custom_value ...
0
votes
2answers
85 views

Complex condition drupal query

I'm trying to add following mysql condition: WHERE DAYOFYEAR(curdate()) <= DAYOFYEAR(DATE_ADD(FROM_UNIXTIME(field_birthday_value, '%y-%m-%d'), INTERVAL (YEAR(NOW()) - ...
0
votes
1answer
182 views

How can I make Drupal/MySql accept special characters in ANSI (without changing the file's encoding)?

I'm developing a custom module where a user (actually an admin of sorts) can upload a CSV file. Based on the contents of this file, certain rows are inserted into a table. I'm now having problems ...
2
votes
1answer
57 views

Is a DB transaction executed when it is committed?

cache_get() is not working as expected when called in a request initiated by drupal_http_request() on the same server. Is it true that the cache_set() immediately before drupal_http_request() doesn't ...
3
votes
3answers
3k views

How to db_select DISTINCT on a particular field in Drupal 7?

I understand that you can specify ->distinct() on the db_select statement so that it only returns distinct values when looking at ALL fields. But what I want is to return distinct values by only ...
1
vote
4answers
270 views

drupal as mobile app backend

Im currently using drupal 7 + commerce for online sales and I have a phonegap app that creates orders. I want to use drupal 7 via a the services module to sync the app sales data with the online ...
0
votes
2answers
62 views

Show table records in view via hook_form

I managed to get things looking a bit better, However I dont know why the checkbox below is showing like the picture. I want to select the checkbox and make it do something with the corresponding ...
0
votes
1answer
28 views

uid is not taking

I'm getting uid by $account->uid on rules when I wrote a query by using this id it returns 0 rows. Below is the code that i'm writing on rules $uid=$account->uid; $sql="select * from profile where ...
0
votes
1answer
2k views

LEFT JOIN with db_select()

I'm trying to do a left join but it isn't working. I have 2 tables: TABLE profile - uid - pid TABLE field_data_field_naam - entity_id - field_naam_value I want to select the field_naam_value ...
0
votes
1answer
22 views

Facets blocks populated with incorrect field data and strange behavior

I'm building a product catalog with faceted search. I'm using Search API, Search API Database Search, and Display Suite. I've created a search server as well as an index which indexes four fields ...
0
votes
1answer
202 views

Correct way for a db_query for nodes between two timestamps

I have a very simple db_query. I want to look for any node created between two timestamps. This query works fine in MySQL shell SELECT nid as id,created as start,title FROM node WHERE created ...
1
vote
1answer
265 views

EntityFieldQuery with “NOT IN” FieldCondition and “=” FieldCondition on the same multi-value field is only processing one FieldCondition

The EFQ is: $query->entityCondition('entity_type', 'node') ->fieldCondition('field_terms_wb_access', 'tid', array_keys($children), 'NOT IN') ->fieldCondition('field_terms_wb_access', ...
0
votes
0answers
33 views

Creating custom content types with a custom module

As a newbie to the Drupal developer community, I'm struggling to understand whether or not a specific approach follows best practices. Regarding persisting data in a custom module, the Database API ...
0
votes
2answers
310 views

Dependent Dropdown based on Database Queries

I've been working through the Drupal 7 AJAX form examples in the Examples module, and am trying to set up a dependent dropdown form element with 2 select lists populated from the database. Basically, ...
2
votes
1answer
31 views

How to do a db api join on “has no value”?

I've got two tables, Foo and Bar. Foo and Bar can be joined by matching Foo's "nid" column to Bar's "col" column. In use, some rows in Foo will have a corresponding entry in Bar, but some won't. I ...
0
votes
1answer
75 views

db_query and db_select not returning anything

I'm trying to use either db_select or db_query with a join in Drupal 7, but not having luck. The query I'm trying to run is: SELECT floormap_counter_expected.counter_name, ...
1
vote
0answers
21 views

I'm getting an error saying I'm inserting a duplicate entry when there isn't one

I have a form for users to update labels for cameras that my Drupal 7 module is displaying. When the user submits the form, first I check to see if the submitted value already exists int he DB: ...
1
vote
0answers
33 views

db_query select nodes created this month [duplicate]

I need to query the database directly using php. I am getting my head around this an how to do this using the Drupal database abstraction layer (using db_select and db_query). I need to limit my query ...
0
votes
1answer
128 views

db_add_field not working

I want to add a new field to node table using db_add_field when intalling a new module, but it seems there is something wrong or missing: here is the code used: /** * Implements hook_schema_alter() ...
1
vote
1answer
132 views

How can I prevent placeholders to wrap the value with single quotes in db_query?

I want to run a select query using db_query. Here is the code: $nid_array = array(24,34,56,7,8); $list_of_nids = implode(',',$nid_array); $query = " SELECT * FROM {table_name} as t ...
0
votes
1answer
39 views

One time db scrub with .install file

I need to scrub a production db to replace paths in the body field. Being a production database, it needs to happen in a time-sensitive, well-documented way with the solution frozen in code. I'd ...
0
votes
0answers
82 views

db_query complete Content Type with all fields automatically

Can I do this automatically in my module without hard coding the list of content type fields: $query = db_select('node', 'n'); $query->join(ALL FIELDS OF THIS CONTENT TYPE, FIELD ALIASES, ONs); ...