Questions tagged [drupal-database]

Drupal provides a standard, vendor-agnostic abstraction layer for accessing database servers.

The Drupal 7 Database API provides a standard, vendor-agnostic abstraction layer for accessing database servers. The API is designed to preserve the syntax and power of SQL as much as possible, but also to:

  • Support multiple database servers easily
  • Allow developers to leverage more complex functionality, such as transactions
  • Provide a structured interface for the dynamic construction of queries
  • Enforce security checks and other good practices
  • Provide modules with a clean interface for intercepting and modifying a site's queries

Further resources

21 questions
10
votes
1 answer

How to select from Drupal with alias

I want to get 1 column from a table in Drupal as 2 aliases. Something like this but with Drupal's query methods.: SELECT name AS label, name AS value FROM node WHERE 1 This Drupal code doesn't set the right alias: $query = db_select('node',…
Eduard Luca
  • 6,514
  • 16
  • 85
  • 137
6
votes
4 answers

How can I keep data in sync during deployment?

I have the occasion to produce Drupal web sites using development, staging, and production environments. Keeping the code in sync between the sites is a simple task using subversion. What is not so simple is propagating changes to the database…
ringmaster
  • 2,879
  • 3
  • 28
  • 31
2
votes
1 answer

How to get the first drop down value as none

I get the desired options from the following code, but I need to add an empty option as the first value of the returned array as '' => 'none', then the rest of values. function dropdown() { return db_select('node', 'n') ->condition('n.type',…
Madhu Nair
  • 428
  • 1
  • 7
  • 20
2
votes
1 answer

If Else in Order by Clause in DB API of Drupal

I have Drupal 7 site. I am using dbApi of Drupal. Now I have a query where I need to order the records. Table Structure:- AlbumId Album Name Album Created Date Album Release Date Now my requirement is if Album Release Date is not NULL then sort…
Kgn-web
  • 7,047
  • 24
  • 95
  • 161
1
vote
1 answer

How can i set up my drupal database correctely?

I guys I'm getting an error while I'm trying to set up my drupal database. the drupal give me this error when i insert the database info, but I'm sure the database info is correct. Warning: count(): Parameter must be an array or an object that…
1
vote
1 answer

Is there any Oracle Driver (module) for Drupal 9?

The Oracle Driver works with Drupal 8, but its composer installation doesn’t work with Drupal 9. https://www.drupal.org/project/oracle My goal is to use the Views Database Connector module to interact with the external Oracle…
0
votes
1 answer

Query Drupal 8 content types with expression

In short, I need to do an entity query while running an expression. I can't find any way to accomplish this. I'm assuming there should be two ways. An entity query with an expression - When I try this I can't get any expressions to work a raw DB…
ilovetoast
  • 65
  • 2
  • 10
0
votes
1 answer

Exporting Content Type Data from Drupal 7 Database

we're in the process of moving a client site from Drupal to Kentico and hoping to speed up some of the content creation by importing data for a custom content type. I don't have development access to the Drupal site to do anything in PHP, I only…
0
votes
1 answer

Flag module causes excessive rows (more than 1million) in database

We are using the flag module in Drupal 8 for a community website. The views are joined with the flag table and the flagging table has grown to more than 1M rows, causing database issue while making the website slow to load. Has anyone encountered…
Naz
  • 13
  • 1
0
votes
1 answer

Drupal 8 and PostgreSQL: How can I use the result of an expression inside a WHERE clause?

Hi there! I construct a database query using Drupal's query interface. With that, I also successfully add an expression that generates a conditional value. The contents of that conditional field is a ISO formatted datestring. I now would like to use…
Chris
  • 65
  • 6
0
votes
2 answers

MySQL to Drupal 7 db_select

I am trying to execute the following mysql query below with drupal 7 db_select. But I cant understand how this can be done. Is anyone can help me to translate the following mysql query into drupal 7 dynamic db query? My main goal is actually sorting…
Robi
  • 23
  • 4
0
votes
0 answers

Admin email is not updating on Drupal7

I have tried to install Drupal 7.x on AWS by using cloudformation but after the installation, while connecting to the RDS admin the administrator email is not updating. In the users table,enter image description here I am able to find all the…
0
votes
1 answer

Drupal 8 SQL statement, avoiding addOrderBy adding some fields in SELECT

I've got the following line in a custom sort plugin for Views and Drupal 8: $formula = '(cas.tier IS NULL)'; $this->query->addOrderBy(NULL, $formula, "ASC", "some_alias"); All I want is for Drupal to add this to the existing query: ORDER BY…
Hubert
  • 369
  • 3
  • 21
0
votes
1 answer

Access denied on Drupal site after changing cPanel password

My colleague changed a cPanel password for a Drupal site. The front-end is now displaying the following error. Error The website encountered an unexpected error. Please try again later. Error message PDOException: SQLSTATE[HY000] [1045] Access…
0
votes
1 answer

How to use join on recent record in db_select drupal 7

I have two tables. Table One xx yy zz Table Two xx-3 xx-2 xx-1 yy-2 yy-1 zz-4 zz-3 zz-2 zz-1 I want to use join between these 2 tables in such a way that it will use latest record from Table Two for each record of table One. i.e. xx join with…
1
2