/** * Fetch a query result row * * @param int $resultType The optional constant indicating what type of array should be produced. * The possible values for this parameter are the constants * **LC_FETCH_OBJECT**, **LC_FETCH_ASSOC**, or **LC_FETCH_ARRAY**. * Default to **LC_FETCH_OBJECT**. * * @return mixed */ public function fetchRow($resultType = LC_FETCH_OBJECT) { if ($this->result === null) { $this->execute(); } if ($this->result) { if ($row = db_fetchAssoc($this->result)) { if ($resultType === LC_FETCH_ARRAY) { return array_values($row); } elseif ($resultType === LC_FETCH_OBJECT) { return (object) $row; } else { return $row; } } } return null; }
function was_call_answered($id) { $query = "SELECT callstate FROM asterisk_log WHERE asterisk_dest_id='{$id}'"; $result = db_checked_query($query); $result = db_fetchAssoc($result); $callstate = $result['callstate']; if ($callstate == 'Ringing' || $callstate == 'Dial') { return 0; } else { return 1; } }
/** * Perform a query on the database and return the array of all results * * @param string $sql The SQL query string * @param array $args The array of placeholders and their values * @param int $resultType The optional constant indicating what type of array should be produced. * The possible values for this parameter are the constants * **LC_FETCH_OBJECT**, **LC_FETCH_ASSOC**, or **LC_FETCH_ARRAY**. * Default to **LC_FETCH_OBJECT**. * * @return array|boolean The result array of objects or associated arrays or index arrays. * If the result not found, return false. */ function db_extract($sql, $args = array(), $resultType = LC_FETCH_OBJECT) { if (is_numeric($args)) { if (in_array($args, array(LC_FETCH_OBJECT, LC_FETCH_ASSOC, LC_FETCH_ARRAY))) { $resultType = $args; } $args = array(); } $data = array(); if ($result = db_query($sql, $args)) { while ($row = db_fetchAssoc($result)) { if (count($row) == 2 && array_keys($row) === array('key', 'value')) { $data[$row['key']] = $row['value']; } else { if ($resultType == LC_FETCH_ARRAY) { $data[] = array_values($row); } elseif ($resultType == LC_FETCH_OBJECT) { $data[] = (object) $row; } else { $data[] = $row; } } } } return count($data) ? $data : false; }