query

How to search for a string in all fields of every table in a MySQL database

Here’s a cool tip: if you want to search for a text string in all fields of all tables of a MySQL database, you can use phpMyAdmin to do this very easily. Here are the steps to search every MySQL database table.

1) Select the desired database

The first step is to select the database you want to search. Don’t select a table — just select the database you want to search. (If you select a table you’ll get a different search form in Step 2.)

A Drupal 8 XML Sitemap generating PHP script alvin May 23, 2016 - 5:25pm

I’m not going to comment on the following code too much or provide support for it, but (a) if you need to create an XML Sitemap for a Drupal 8 website, and (b) you don’t like the Drupal 8 sitemap modules that are available, then (c) this PHP script can serve as a starting point for you.

How to list MySQL database table column names without the table formatting

If you want to list all of the MySQL database table column names (field names) as a simple list of names, with each column name listed on a separate line, just follow these steps.

First, start MySQL with the -sN options, like this:

$ mysql -sN -u root -p

Then execute a query like this:

Scala: A quick look at the Slick database library

This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 16.9, “A quick look at the Slick database library.”

How to connect to a MongoDB database and insert data with Scala

This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 16.3, “How to connect to a MongoDB and insert data with Scala.”

Problem

You want to use the MongoDB database with a Scala application, and want to learn how to connect to it, and insert and retrieve data.

Scala: How to connect to a SQL database with the Spring Framework

This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 16.2, “How to connect to a database with the Spring Framework.”

Problem

You want to connect to a database using the Spring Framework. This gives you a nice way to add connection pooling and other capabilities to your SQL code.

How to connect to a MySQL database with Scala and JDBC

This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 16.1, “How to connect to a MySQL database with Scala and JDBC.”

Problem

You want to connect to a MySQL database (or any other database with a JDBC driver) from a Scala application using “plain old JDBC.”

Solution

Use JDBC just like you would in a Java application. Download the MySQL JDBC driver, and then access your database with code like this:

Sencha ExtJS Store “findRecord” query examples

Here are a few short examples of how to find an object in a Sencha Store (ExtJS or Sencha Touch).

As a first example, imagine that you have a Store of users, and want to find a user with the first name of “Alvin”. Assuming that your user model has a field named firstName, your query would look like this:

var user = usersStore.findRecord('firstName', 'Alvin');

After this query you can use the user object just as though you had created it by hand. (The object returned is a Model instance.)

Handling Drupal SQL exceptions (db_insert, db_update, db_delete)

While developing a Drupal module, I just ran into a situation where it may be common for users to generate SQL exceptions. I have a 'unique' limit on several of my database tables, essentially saying that certain name fields must be unique for the current project. As you can imagine, it's extremely easy to enter a duplicate name, and while doing a SQL INSERT that can easily lead to a SQL exception.

As a result, I dug around and found a way to handle SQL exceptions in Drupal queries. My current problem is with a Drupal 7 db_insert query, and I handled it like this: