Delicious Bookmark this on Delicious Share on Facebook SlashdotSlashdot It! Digg! Digg



PHP : Function Reference : SESAM Database Functions : sesam_diagnostic

sesam_diagnostic

Return status information for last SESAM call ()
array sesam_diagnostic ( )

Example 2210. Displaying SESAM error messages with error position

<?php
// Function which prints a formatted error message,
// displaying a pointer to the syntax error in the
// SQL statement
function PrintReturncode($exec_str)
{
   
$err = Sesam_Diagnostic();
   
$colspan=4; // 4 cols for: sqlstate, errlin, errcol, rowcount
   
if ($err["errlin"] == -1)
       --
$colspan;
   if (
$err["errcol"] == -1)
       --
$colspan;
   if (
$err["rowcount"] == 0)
       --
$colspan;
   echo
"<table border=\"1\">\n";
   echo
"<tr><th colspan=\"" . $colspan . "\"><span class=\"spanred\">ERROR:</span> ".
       
htmlspecialchars($err["errmsg"]) . "</th></tr>\n";
   if (
$err["errcol"] >= 0) {
       echo
"<tr><td colspan=\"" . $colspan . "\"><pre>\n";
       
$errstmt = $exec_str . "\n";
       for (
$lin=0; $errstmt != ""; ++$lin) {
           if (
$lin != $err["errlin"]) { // $lin is less or greater than errlin
               
if (!($i = strchr($errstmt, "\n")))
                   
$i = "";
               
$line = substr ($errstmt, 0, strlen($errstmt)-strlen($i)+1);
               
$errstmt = substr($i, 1);
               if (
$line != "\n")
                   echo
htmlspecialchars($line);
           } else {
               if (! (
$i = strchr ($errstmt, "\n")))
                   
$i = "";
               
$line = substr ($errstmt, 0, strlen ($errstmt)-strlen($i)+1);
               
$errstmt = substr($i, 1);
               for (
$col=0; $col < $err["errcol"]; ++$col) {
                   echo (
substr($line, $col, 1) == "\t") ? "\t" : ".";
               }
               echo
"<span class=\"spanred\">\\</span>\n";
               echo
"<span class=\"normal\">" . htmlspecialchars($line) . "</span>";
               for (
$col=0; $col < $err["errcol"]; ++$col) {
                   echo (
substr ($line, $col, 1) == "\t") ? "\t" : ".";
               }
               echo
"<span class=\"spanred\">/</span>\n";
           }
       }
       echo
"</pre></td></tr>\n";
   }
   echo
"<tr>\n";
   echo
" <td>sqlstate=" . $err["sqlstate"] . "</td>\n";
   if (
$err["errlin"] != -1)
       echo
" <td>errlin=" . $err["errlin"] . "</td>\n";
   if (
$err["errcol"] != -1)
       echo
" <td>errcol=" . $err["errcol"] . "</td>\n";
   if (
$err["rowcount"] != 0)
        echo
" <td>rowcount=" . $err["rowcount"] . "</td>\n";
   echo
"</tr>\n";
   echo
"</table>\n";
}

if (!
sesam_connect ("mycatalog", "phoneno", "otto"))
 die (
"cannot connect");

$stmt = "SELECT * FROM phone\n" .
       
" WHERE@ LASTNAME='KRAEMER'\n" .
       
" ORDER BY FIRSTNAME";
if (!(
$result = sesam_query ($stmt)))
   
PrintReturncode ($stmt);
?>

Change Language


Follow Navioo On Twitter
sesam_affected_rows
sesam_commit
sesam_connect
sesam_diagnostic
sesam_disconnect
sesam_errormsg
sesam_execimm
sesam_fetch_array
sesam_fetch_result
sesam_fetch_row
sesam_field_array
sesam_field_name
sesam_free_result
sesam_num_fields
sesam_query
sesam_rollback
sesam_seek_row
sesam_settransaction
eXTReMe Tracker