Julitillo
Julitillo

Reputation: 73

How to filter records with a not null value in Moodle?

I am trying to select a record with the mimetype field with a non-null value,

$file = $DB->get_record('table', array('itemid' => $id_imagen, 'component' => 'user', 'mimetype' => 'is not null'));

Is there any way to get this using get_record?

Upvotes: 1

Views: 911

Answers (1)

Julitillo
Julitillo

Reputation: 73

I answer my own question in case this can help someone

No, it is no possible to use IS NOT NULL or others with get_record function. You can acomplish it using function get_record_sql like this:

$file = $DB->get_record_sql("SELECT * FROM table WHERE itemid = " . $id_imagen . " AND component = 'user' AND mimetype IS NOT NULL");

Upvotes: 2

Related Questions