pod_query

(Since 1.2.0) -- execute a raw SQL query
function pod_query($sql, $error = 'SQL failed', $results_error = null, $no_results_error = null)
pod_query() is a MySQL abstraction layer. It is especially useful for providing additional information whenever a query fails. It automatically returns the ID of any item created using an INSERT statement.

Parameters

ParameterTypeDetails
$sql STRING the query to execute
$error STRING (optional) the message to return on failure
$results_error STRING (optional) trigger an error message if there are any results (used to prevent duplicates)
$no_results_error STRING (optional) trigger an error if no error occurred, but no records are found

Examples

Select all people with the first name of "Bill":
<?php
$result = pod_query("SELECT first_name, last_name FROM wp_pod_tbl_person WHERE first_name = 'Bill'");
while ($row = mysql_fetch_assoc($result))
{
    echo '

' . $row['first_name'] . ' ' . $row['last_name'] . '

'; } ?>
Make sure the first name of "Bill" doesn't exist:
<?php
pod_query("SELECT id FROM wp_pod_tbl_person WHERE first_name = 'Bill' LIMIT 1", 'No dupes allowed', 'That first name already exists!');
?>
Insert a new "event" and return its ID:
<?php
$datatype_id = 4; // assuming your 'event' Pod has an ID of 4
$event_id = pod_query("INSERT INTO wp_pod_tbl_event (name) VALUES ('New Event')");
$pod_id = pod_query("INSERT INTO wp_pod (tbl_row_id, datatype, name) VALUES ($event_id, $datatype_id, 'New Event')");
?>
See Also