Ejemplo 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>\n"; echo "<TR><TH COLSPAN=".$colspan."><FONT COLOR=red>ERROR:</FONT> ". 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") print 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 "<FONT COLOR=RED><BLINK>\\</BLINK></FONT>\n"; print "<FONT COLOR=\"#880000\">".htmlspecialchars($line)."</FONT>"; for ($col=0; $col < $err["errcol"]; ++$col) echo (substr ($line, $col, 1) == "\t") ? "\t" : "."; echo "<FONT COLOR=RED><BLINK>/</BLINK></FONT>\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); ?>
|
|