admin管理员组

文章数量:1289511

I'm trying to set up a query for routing on Kamailio so that it asks a SQL database.

This is the information that I have in the configuration file:

#!ifdef WITH_MYSQL
loadmodule "db_mysql.so"
modparam("db_mysql", "db_url", "mysql://kamailio:Pablo3090@localhost/kamailio")
#!endif

request_route {
    # Handle SIP OPTIONS (Heartbeat)
    if (is_method("OPTIONS")) {
        sl_send_reply(200, "OK");
        exit;
    }

    if (is_method("INVITE")) {
        xlog("L_INFO", "Handling INVITE request\n");

        # Query the database for the contact domain based on phone number
        if (sql_query("kamailio", "SELECT contact_domain FROM sip_routing WHERE phone_number='$rU'", "result")) {
            if ($dbr(result=>rows) > 0) {
                $var(contact_domain) = $dbr(result=>[0][0]);
                append_to_reply("Contact: <sip:$rU;tgrp=teams_trunk;trunk-context=teams_tk@$var(contact_domain);user=phone>\r\n");
            } else {
                xlog("L_WARN", "No routing found for $rU\n");
            }
            sql_query_free("result");
        } else {
            xlog("L_ERR", "Database query failed!\n");
        }

        sl_send_reply("300", "Multiple Choices");
        exit;
    }
}

However when I debug using

sudo kamailio -f /etc/kamailio/kamailio.cfg -DD -E 

it fails with this error:

0(55419) CRITICAL: [core/cfg.y:4017]: yyerror_at(): parse error in config file /etc/kamailio/kamailio.cfg, line 553, column 110: unknown command, missing loadmodule?

The line relates to

if (sql_query("kamailio", "SELECT contact_domain FROM sip_routing WHERE phone_number='$rU'", "result")) {

I have searched but I can't seem to find a fix, would anyone have any idea how to fix the query?

本文标签: SIP Kamailio SQL query failingStack Overflow