Esempio 1. 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); ?>
|
|