Menu

How to Implement SQL statement in iTOP?

2014-03-26
2014-03-27
  • jitsobullet

    jitsobullet - 2014-03-26

    Hi,

    Can someone please show me how i can execute an SQL query from within the Contract Class.

    Currently i am trying:

    ~~~~~~~
    $sSQL = "SELECT name from contract'";
    $resQuery = CMDBSource::Query($sSQL);
    $aRow = mysqli_fetch_assoc($resQuery);
    ~~~~~~~~

    But unfortunately this returns errors:

    Error: Failed to issue SQL query: query = SELECT name from contract', mysql_error = , mysql_errno = 0.

    Any help please?

     
  • Pankaj khurana

    Pankaj khurana - 2014-03-27

    Hi jitsobullet,

    Please remember before running any query inside code,please test your query in admin module .
    for example your query is wrong there

    SELECT Contract WHERE name LIKE '%A%'

    For example you want to count number of user request open then query for this like

    $sOQL = 'SELECT UserRequest WHERE org_id = :org_id AND status NOT IN ("closed", "resolved")';
    $oSearch = DBObjectSearch::FromOQL($sOQL);
    $iUser = UserRights::GetContactId();
    if ($iUser > 0)
    {
        $oSearch->AddCondition('caller_id', $iUser);
    }
    $oSet = new CMDBObjectSet($oSearch, array(), array('org_id' => $oUserOrg->GetKey()));
    return $oSet->Count();
    

    ok i hope this will help you

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.