Topics related to the database API implemented by Drupal.

learn more… | top users | synonyms (1)

0
votes
1answer
24 views

What is “alias” in db_select() function?

Beginner Drupal Developer. The drupal API didn't provide info for what purpose the $alias must be used in db_select? And what is that anyway?
0
votes
0answers
9 views

How to convert certain db_query to db_select using WHERE, OR and AND conditions [duplicate]

I have this db_query: $transactions = db_query("SELECT * FROM {funds_transactions} WHERE uid='$user->uid' OR type='Transfer' AND reference=$user->uid"); And I need to convert it to db_select. ...
0
votes
0answers
41 views

Drupal db_select Query to over ride empty array inside NOT IN ()

I had a query (part of a big query): $query->add_where(1, '10', db_select('users_roles', 'r') ->fields('r', array('rid')) ->where('r.uid = users_node__users_roles.uid'), 'NOT ...
2
votes
0answers
29 views

DB API: How to implement an enumerated field using hook_schema?

I need to have a field in my database that is shall hold a limited set of enumerated values. The MySQL ENUM type is not one of the predefined Drupal data types. So how do one implement a field to ...
0
votes
0answers
28 views

db_select pager query orderBy signed int

I have an INT 'weight' field for some nodes that runs -20 through to +20 and want to order the nodes so that -20 is at the top, but, as far as I can tell I'm getting them in string order. I've tried ...
0
votes
3answers
33 views

Limit the results returned by 'published'

I am new to the Database API and SQL queries in general. I needed to create a custom module that could be given a list of fields and would output the average value of each of these fields. I am ...
0
votes
1answer
24 views

Displaying and selecting data from a database in a module

I have a database table (gpx_api) with the following fields: runID userID score distance pace speed gpx_path missionID startTime duration I want to display all of these fields ...
6
votes
1answer
143 views

Preventing SQL injection

In Drupal 6, queries are issued with db_query(). Using %-modifiers, query arguments are substituted into the query after being filtered. Strings %s (and only strings) are ultimately run through ...
0
votes
1answer
105 views

db_update add value to field [duplicate]

I want use db_update to update a field,instead of update a field with new value (replace) , I want add a value to last value, I know I can do it with mysql command UPDATE ...
0
votes
1answer
27 views

Help with a db_select() not returning results when it *should*

I'm having trouble figuring out why the db_select() is not returning any results. Long story short, if I pass the results of $results->execute() through a foreach ($results as $result), I don't ...
1
vote
1answer
56 views

How to query for null in nested db_or conditional

I am trying to perform a query as listed below (notice the check for NULL) $query = db_select('node', 'n'); /* add fields and joins... */ $query->condition(db_or() ->condition(db_and() ...
0
votes
2answers
37 views

Accessing field inside a block

I have created a block to display flash content. All it needs a a variable to be assigned dynamically from the content to flashVar. I created a field called myfile path in the custom content type. ...
3
votes
2answers
60 views

Should I use content-types or database abstraction layer?

I am building an admin site for my brother's property management company. The design seems pretty straight forward. I need a database with tables to store: Estates. Each estate has a number or ...
0
votes
2answers
50 views

How to order unions separately in db_select?

I have a UNION query, where the second part of the UNION should be ordered separately, not the complete UNION. The resulting query should look like this: ( SELECT id, fname FROM tab1 WHERE fname = ...
0
votes
1answer
26 views

Setting up Multiple Databases on a current site

I'm having issues with my current shared hosting provider due to my core database exploding upwards of 1GB due to cache_form. I've been looking at trying to offload the cache and revisions databases ...
0
votes
0answers
43 views

Drupal 7 with standalone PHP service

I'm trying to create a stand alone PHP page that going to be service. I know about Services module, but I need the stand alone page. This page is localed under my Drupal root directory in _services ...
0
votes
1answer
55 views

The most efficient way to query the user table and custom profile info based on UID

I am trying to grab a specific users profile info + custom profile fields WHERE uid = X, I have used the views module currently and copied that sql however that creates a massive query. I was ...
1
vote
2answers
173 views

Using db_select with subqueries

Here's an example raw query of what I am trying to achieve with database API: SELECT * FROM ( SELECT n.nid AS entity_id, n.uid, n.title, node_body.body_value, ...
1
vote
2answers
92 views

How to create db table while installing a module?

I want to create a table in Drupal while installing a module (custom module which is crated by me). I tried in the below way, but I could not able to create a table in Drupal db. what am I missing, ...
2
votes
2answers
203 views

Drupal 7 db_error() equivalent?

I'm trying to figure out how to get the last database error after a query fails, and I'm having trouble finding the appropriate function. It seems up until Drupal 7 there was a db_error() function ...
0
votes
0answers
19 views

Query treating large number as a string

I am trying to run a select statement on a table for a column. The column is decimal(20,0) unsigned. A majority of the entries can be found using the select statement: db_query('SELECT * FROM ...
1
vote
1answer
562 views

db_select condition with subquery causes PDOexception

I want to build a relative simple select query with a subquery in its condition. What I want to achieve is to get the list of users updated after a given timestamp. The working SQL-Query which I ...
1
vote
1answer
62 views

How to implement ORDER BY SUBSTRING in db_query

I am migrating comments from a Drupal 6 site into Drupal 7 - but I am importing into the Reply module https://drupal.org/project/reply because the comments were on a Profile node in Drupal 6 but now ...
2
votes
1answer
173 views

SQL left join query using Drupal DB Layer

The following (my)?sql query performs a left joins of node table with url_alias table by matching a node with its url alias, and returns rows with the node's title, date created, type, and url-alias: ...
2
votes
1answer
37 views

How to make weights continous with db_update?

With pure MySQL, I can do something like: SET @weight:=0; UPDATE mymodule_table SET mymodule_weight=@weight:=@weight+1 ORDER BY mymodule_weight, mymodule_id; Is there a Drupal way to achieve ...
0
votes
1answer
336 views

Can't change quantity of line item with rules

I created a rule that checks for the quantity of a product while adding to cart and while proceeding to the second step of checking out. The action sends a warning message to the site that says you ...
0
votes
3answers
282 views

How can I run a sql query from a file in Drupal?

I have a module that will be used as a location finder, and it needs to create a table on install that will hold zip codes and their location. That's easy to do. However, I also need to populate that ...
0
votes
1answer
327 views

Get a taxonomy id(tid) from a node id (nid)

if($node->type=='student') { $nid = $node->nid; print_r("The node id is: ".$nid.'<br/>'); $tid =db_query('SELECT tid FROM {taxonomy_index} WHERE nid = :nid', ...
0
votes
1answer
32 views

Get the highest Matched output in result

I have a table like this Now my requirement is like below:- I have to fetch all Content ID related to User Id-31. Here the matching content id are 225,178. I am able to retrieve this. Now I want ...
1
vote
2answers
169 views

Insert an article and fields with db_insert function or SQL

I want to add an article to the db using db insert along with its field like tags and image. A sample code i tried(below) is adding data to the db but I can't find any entry in the ...
0
votes
3answers
105 views

Accessing Drupal database for read purposes

I'm interested in analyzing various aspects of the content in our Drupal site involving node meta data such as type, name, creation date, etc. I know I can create views to show some informaiton and I ...
0
votes
2answers
1k views

PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column

I am tring to perform the following sql query to check if the name that was inserted to the form already created as taxonomy name. But I keep getting this error message: PDOException: ...
0
votes
0answers
149 views

create page were i display rows of custom table from database and filter it using form

I want to create page were i display rows of custom table from database. And i want to filter this table using form. i am new in drupal API here is my code(It looks big but actually it is easy to ...
1
vote
1answer
68 views

What is the use of @db_query? [closed]

I have used db_query to retrieve table rows from database. Recently I noticed, some people use @db_query instead of db_query. I dont see any difference with the two. Is it doing any special ...
-1
votes
1answer
111 views

How to use db API addExpression [closed]

I am trying to find a way of creating a view of both a custom entity type and a node. I was following this as a guide: https://drupal.org/node/748844 (see the way end for the D7 implementation, I have ...
1
vote
1answer
196 views

How to get number of results from MySQL query without getting all result data?

For a Google Maps application, I built an AJAX call that dynamically checks whether there are markers in a given viewport range. All marker information is stored in a node (note that I am using ...
0
votes
1answer
283 views

Closing MySql Connection in Drupal7

How can i explicitly close a MySql Connection in Drupal 7 ? I have a requirement of insertig back to rows to a DB table in drupal.. I tried using db_insert/db_update and db_query .. In Both cases i ...
0
votes
0answers
80 views

pager replaced in ajax callback

I have a page with multiple elements and pager. They are both created in the same function. Next to this i have a search box, and after clicking "search", ajax callback calls this same function and ...
2
votes
1answer
69 views

What is the difference between limit(1) and range(0, 1)?

In a query I tried using limit(1); I got a WSOD, but when I use range(0,1) I don't get any WSOD. What is the basic difference between limit(1) and range(0, 1)?
0
votes
0answers
66 views

PDOexception: SQLSTATE[HY000] timeout errors when deleting/adding or even trying to flush cache

I don't know why this suddenly started happening last week. How can I get more details, and possibly hints as to what module or data is causing this? Sometimes, trying the delete several times helps, ...
1
vote
1answer
171 views

How to use use db_rewrite_sql() with db_query() in D7?

I read article where it was written to use db_rewrite_sql($query). In Drupal 7, you need to use addTag('node_access') along with `db_select(). I have a query with 8 columns and 4 conditions; for ...
1
vote
2answers
103 views

How can I replace a value already present in the database?

Is there a way for db_insert() to overwrite existing entries?
0
votes
0answers
113 views

Connect to the database in blocks

I want to use some query of database in blocks with Drupal Database API. I try a lot but my code doesn't work. It is a code that I made by Drupal Database API. <?php $now =date("YmdHis"); $con = ...
0
votes
0answers
315 views

Troubleshoot PDOExeption SQLSTATE[22007]: Invalid datetime format: 1366

I am evaluating NodeStream with its web newspaper product. When I create content with devel generate, I am presented with: PDOException: SQLSTATE[22007]: Invalid datetime format: 1366 Incorrect ...
1
vote
1answer
445 views

db_insert in Drupal 7 without field names

I have the following INSERT in a db_query, but feel like I should convert it to a db_insert, but can't figure out the syntax: INSERT INTO {mytable} VALUES (23, 'foo', 'bar', 42) This example is ...
1
vote
2answers
81 views

db_query performance

This is a more general question about db_query() performance. I have this function to create an API resource with Services module, and I need to get about 10 fields belonging to several nodes. ...
1
vote
2answers
160 views

Update Mysql table row

I'm new to Drupal and its SQL API, and I am trying to update a row in a table I created. // Admin form function admin_Form($form, &$form_state) { $dbval = getVals(); $form = array(); ...
0
votes
1answer
55 views

db_delete on click on a link in module contents display

I've made a module displaying a set of fields from the database. I would like to add a "delete" link at the end of each row be able to delete the row in the database on click. I made it in my module ...
2
votes
1answer
187 views

How to skip first row in a dynamic query?

I've not yet found the right way to use ->range($offset,$limit) in a dynamic query to skip first result, but without limiting the resultset (LIMIT clause). The only workaround I've found is to use an ...
0
votes
0answers
101 views

problem to add rich text in a field textarea on Drupal 7

I tried to use ckeditor on my drupal 7 form fields, but when I did the integration of the fields in the database, it records "array", someone has an idea how? here is my code: $defaults = array( ...