PreviousNext
Help > API Functions > Native database access > Complete examples
Complete examples

 

Example 1:

 

The PHP program uses the following commands:

         i5_connect

         i5_open

         i5_seek

         i5_fetch_row

         i5_match

         i5_edit

         i5_setvalue

         i5_update

 

            <?php

 

 

            $user = "user";

            $pass = "pwd";

            $connect = "power8";

            $property = array (I5_OPTIONS_JOBNAME => "PHPDQ" );

 

            $TraceLvl = 4;

            $TraceFile = "CR/TRACEPHP2";

 

            $Hdlcon = i5_connect($connect, $user, $pass, $property);

 

                    $fil = i5_open("EASYCOMXMP/S_ORDER", I5_OPEN_READWRITE,$Hdlcon);

                    if(is_bool($fil))

                    {

                                         print_r("i5_open error : ".i5_errormsg().'<br/>');

                    }

                    else

                    {

  

                                         $seek = array("1003");

                                         $ret = i5_seek($fil, I5_EQ, $seek);

                                         if (!$ret)

                                         {

                                                             printError(i5_error());

                                                             print_r("i5_seek error : ".i5_errormsg().'<br/>');

                                         }

                                         else

                                         {

                                                             $rec = i5_fetch_row($fil, I5_READ_SEEK);

 

                                                             if (is_bool($rec))

                    trigger_error("i5_fetch_row error : ".i5_errormsg(), E_USER_ERROR);

                                                            

                                                             $ret = i5_match($fil);

                                                             if ($ret)

                                                              echo "Record found<BR>";

                                                             else

                                                              echo "Record not found<BR>";

                                        

                                                             $ret = i5_edit($fil, I5_EDIT_ONE);

                                        

                                                             if(!$ret)

                                                             {

                                                                                 print_r("i5_edit error : ".i5_errormsg().'<br/>');

                                                             }

                                                             else

                                                             {

                                                                                 // Modifies ONE current record field value

                                                                                 $ret = i5_setvalue($fil, "SHIPVIA", "MAIL");

                                                                                 $ret = i5_update($fil);

                                                             }

                                         }

                    }

 

?>

 

 

 

Example 2:

 

The PHP program uses the following commands:

         i5_connect

         i5_open

         i5_seek

         i5_fetch_row

         i5_range_from

         i5_range_to

          i5_fetch_array

          i5_fetch_assoc

 

            <?php

 

 

            $user = "user";

            $pass = "pwd";

            $connect = "power8";

            $property = array (I5_OPTIONS_JOBNAME => "PHPDQ" );

 

            $TraceLvl = 4;

            $TraceFile = "CR/TRACEPHP2";

 

            $Hdlcon = i5_connect($connect, $user, $pass, $property);

 

       

                    $file = i5_open('EASYCOMXMP/S_ORDER');

                    if(is_bool($file))

                    {

                                         print_r("i5_open error : ".i5_errormsg().'<br/>');

                    }

                    else

                    {

                   

 

                                         $first = array('ORDER_ID' => '1003');

                                         $last = array('ORDER_ID' => '1010');

 

                                         $ret = i5_range_from($file, true, $first);

                                         if (!$ret) {

                                         trigger_error('i5_range_from error : '.i5_errormsg(), E_USER_ERROR);

                                         }

                   

                                         $ret = i5_range_to($file, false, $last);

                                         if (!$ret) {

                                         trigger_error('i5_range_to error : '.i5_errormsg(), E_USER_ERROR);}

                                        

 

                                         echo 'i5_fetch_row : <BR>';

                                         $ret = i5_seek($file, I5_FIRST);

                                         while ($tab = i5_fetch_row($file))

                                         {

                                                             printf('%s (%s)<BR>', $tab[3], $tab[5]);

                                         }

 

                                         echo '<BR>i5_fetch_array : <BR>';

                                         i5_seek($file, I5_FIRST);

                                         $tab = i5_fetch_array($file, I5_READ_SEEK);

                                         while ($tab)

                                         {

                                                             printf('%s (%s)<BR>', $tab[3], $tab[5]);

                                                             $tab = i5_fetch_array($file, I5_READ_NEXT);

                                         }

 

                                         echo '<BR>i5_fetch_assoc : <BR>';

                                         $tab = i5_fetch_assoc($file, I5_READ_FIRST);

                                         while ($tab)

                                         {

                                                             printf('%s (%s)<BR>', $tab['CUST_ID'], $tab['SHIPVIA']);

                                                             $tab = i5_fetch_assoc($file, I5_READ_NEXT);

                                         }

 

                    }

 

?>