Inserting DB Records in a .install file

1 reply [Last post]
Last seen: 10 years 21 weeks ago
Joined: 2011-06-04

I've got a .install file where I describe my database table schema. The table in question has a dozen or so pre-defined records in it that track key values, etc. I'd like to be able to insert those records as part of the install process, in the .install file rather than check whether to insert or update the record in the module that uses them. Is there a method that would allow me to do that? I attempted to describe a function in the .install file that does all of the inserts. But I got error messages that the database table didn't exist.

Alternatively, what's the proper method to determine whether a record exists in the database table or not? I know how to insert a record. I know how to update a record. I just don't know what the conditional logic should be to see if the the record exists or not and then take the appropriate action.


Last seen: 10 years 21 weeks ago
Joined: 2011-06-04
Never mind

Apparently that is what module_install is for!

Add to playlist

Add to , or

Add to new playlist:

Add to playlist
This is a member-only feature
But, it's easy to become a member

Add to cart:

Contact us

Below are the supported keyboard shortcuts for our video player.

Start / stop video
Go to next video
Go to previous video
Increase or decrease player speed by 20%
Skip ahead or go back by 15 seconds
Jump to a percentage (2 is 20%, for example)
Toggle full screen
Videos Pricing More Search
BuildAModule Logo Icon BuildAModule Logo Icon
Become a member!
1 month
6 months
10% off
12 months
20% off
All memberships come with the following:
24 / 7 access to the entire 1800+ video library
An innovative video player with a rolling transcript
Extensive Drupal and cross-platform training
A thorough and thoughtful training style
Progress tracking
Take notes on specific video sections
Intuitive multi-user management
How many users?
Go solo with a single user, or give multiple team members access through one account and get discounts by bundling multiple users into a single membership.