<html> <h2>Demo 5 - Select a count from a table</H2> <?php /*********************************************************************/ function chk_ifx_err1($result_id) /*********************************************************************/ { /************************************************** The ifx_error function return the following string: x [SQLSTATE = aa bbb SQLCODE=cccc] where x = space : no error E : error N : no more data W : warning ? : undefined *************************************************/ $err_string = ifx_error($result_id); if ($err_string[0] != ' ') { printf("<BR>Informix error: %s", ifx_errormsg()); die; } } $database = "video"; $server = "lapdog_tcp"; $login = "username"; $password = "password"; $dbs = $database . "@" . $server; $connect_id = ifx_pconnect($dbs,$login,$password); if (!$connect_id) { echo "Unable to connect to Informix database<br>\n"; chk_ifx_err1($connect_id); } else { echo "Informix connection successful! <BR>"; } if ($connect_id) { $statmt_txt = "select count(*) count from vhs where type_code = 'ST1' "; $statmt_id1 = ifx_query($statmt_txt,$connect_id); // EXECUTE SQL if (!$statmt_id1) { echo "Unable to execute Informix sql statement<br>\n"; echo "$statmt_txt<br>\n"; chk_ifx_err1($statmt_id1); } $row = ifx_fetch_row($statmt_id1); // FETCH RESULT OF COUNT INTO ARRAY if (!$row) { echo "Unable to fetch Informix result<br>\n"; echo "$statmt_txt<br>\n"; chk_ifx_err1($statmt_id1); } $num_rows_selected = sprintf("%d",$row[count]); // FORMAT COUNT INTO VARIABLE echo "<html>"; echo "$num_rows_selected rows selected <BR>"; // DISPLAY RESULT IN HTML echo "</html>"; ifx_free_result ($statmt_id1); } ?> </html>