Problem with the connexion Database

Hello,

I am a new user of SuiteCRM, I try to create an requete who selection my table cand_list.

Can you help me with my requete ?

$requete_select = $GLOBALS['db']->prepare("SELECT * FROM cand_list WHERE created_by = :created_by"); 
    $requete_select->bindValue('created_by', $GLOBALS['current_user']->id, PDO::PARAM_INT);
    $requete_select->execute();
    $infos = $requete_select->fetch();
    $requete_select->closeCursor();

      echo $infos['id'];

Where did you get this code from? I’ve never seen PDO prepared queries in SuiteCRM… :thinking:

Hi, @Robin17, as you are not getting any data from Outer source, so you don’t need to query like this, just be simple

$current_user_id=$GLOBALS['current_user']->id;
$result=$GLOBALS['db']->query("SELECT * FROM cand_list WHERE created_by ='$current_user_id' AND deleted=0"); 
if ($result->num_rows > 0) {
 while ($row= $GLOBALS['db']->fetchByAssoc($result)) {
//Complete Row
print_r($row);
//and then you can get the fields like id
$id=$row['id'];
}
}

Hope this will help.
Thanks

1 Like

Hi,
it’s perfect
thank you very much for you help :smile:

1 Like

Hi, You are welcome !!