Problem with the connexion Database


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);
    $infos = $requete_select->fetch();

      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

$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
//and then you can get the fields like id

Hope this will help.

1 Like

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

1 Like

Hi, You are welcome !!