Fetch Particular table column value

2013-06-11
2013-06-18
  • Pankaj khurana

    Pankaj khurana - 2013-06-11

    Hello,

    Again need a help to solve a problem.

    if i want to fetch particular column value..
    like from person table I would like to fetch mobile_phone column value of particular person.
    how can i do this??..

    Please help me or guide me...

    Thanks in advance...

    Regards
    Pankaj

     
  • Denis

    Denis - 2013-06-11

    Hi Pankaj,

    iTop is based on what we call an ORM (Object Relational Mapper) layer. This means that, inside iTop, we always handle complete PHP objects and not database columns.

    Imagine that you want to print the name of all persons whose name contains 'e':

    $sOQL = "SELECT Person WHERE name LIKE '%e%'";
    $oSet = new DBObjectSet(DBObjectSearch::FromOQL($sOQL));
    while($oPerson = $oSet->Fetch())
    {
        echo $oPerson->Get('name').' ';
    }
    

    Now if you want to retrieve only the 'name' attribute of the Person, you can speed-up the query by limiting the columns loaded by the ORM. The code would look like:

    $sOQL = "SELECT Person WHERE name LIKE '%e%'";
    $oSet = new DBObjectSet(DBObjectSearch::FromOQL($sOQL));
    $oSet->OptimizeColumnLoad(array('name'));
    while($oPerson = $oSet->Fetch())
    {
        echo $oPerson->Get('name').' ';
    }
    

    Hope this helps,

    Denis

     
  • Pankaj khurana

    Pankaj khurana - 2013-06-11

    Sorry sir bit gives error...

    $sOQL = "SELECT Service WHERE name LIKE '%S%'";
    $oSet = new DBObjectSet(DBObjectSearch::FromOQL($sOQL));
    $oSet->OptimizeColumnLoad(array('name'));
    while($oPerson = $oSet->Fetch())
    {
    $name= $oPerson->Get('name').'...\n ';
    }

    Error: Unknown filter code, found 'name' in: SELECT Service WHERE name LIKE '%S%'.

    Notice: Undefined index: friendlyname in C:\wamp\www\web3.1.0\core\metamodel.class.php on line 830

    Fatal error: Call to a member function LoadInObject() on a non-object in C:\wamp\www\web3.1.0\core\dbobject.class.php on line 420

     
  • Pankaj khurana

    Pankaj khurana - 2013-06-11

    Now its gives error....

    $sOQL = "SELECT Service WHERE name LIKE \'%A%\'";
    $oSet = new DBObjectSet(DBObjectSearch::FromOQL($sOQL));
    $oSet->OptimizeColumnLoad(array('name'));
    while($oPerson = $oSet->Fetch())
    {
    $aa= $oPerson->Get('name').' ';
    // print_r($aa);
    }

    Error: Unexpected input at line 1: .

    Notice: Undefined index: friendlyname in C:\wamp\www\web3.1.0\core\metamodel.class.php on line 830

    Fatal error: Call to a member function LoadInObject() on a non-object in C:\wamp\www\web3.1.0\core\dbobject.class.php on line 420

     
  • Pankaj khurana

    Pankaj khurana - 2013-06-11

    Hello Denis sir,

    May i know that i am missing some thing,this query is not running ...gives error...
    ....

     
  • Pankaj khurana

    Pankaj khurana - 2013-06-18

    Error: Wrong value for field name in ORDER BY spec, found 'friendlyname' while expecting a value in {name, org_id, organization_name, servicefamily_id, servicefamily_name, description, documents_list, contacts_list, status, customercontracts_list, providercontracts_list, functionalcis_list, servicesubcategories_list, coverage_window_id, holiday_id, auto_assignement}.

    Notice: Undefined index: friendlyname in C:\wamp\www\web3.1.0\core\metamodel.class.php on line 830

    Fatal error: Call to a member function LoadInObject() on a non-object in C:\wamp\www\web3.1.0\core\dbobject.class.php on line 420

     
  • Pankaj khurana

    Pankaj khurana - 2013-06-18

    Hello Denis sir,

    why this error comes when i run query...this query works fine when..i tested in RUN OQL...

    Please quide me....

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks