PHP can take user input from a web form, pass it to the database server as a SQL query, and display the result that is returned. The following example demonstrates a simple web form that gives the user the ability to query the sample database using SQL statements and display the results in an HTML table.
The source code for this sample is contained in your SQL Anywhere installation in a file called webisql.php.
<?php echo "<HTML>\n"; $qname = $_POST["qname"]; $qname = str_replace( "\\", "", $qname ); echo "<form method=post action=webisql.php>\n"; echo "<br>Query: <input type=text Size=80 name=qname value=\"$qname\">\n"; echo "<input type=submit>\n"; echo "</form>\n"; echo "<HR><br>\n"; if( ! $qname ) { echo "No Current Query\n"; return; } # Connect to the database $con_str = "UID=DBA;PWD=sql;ENG=demo;LINKS=tcpip"; $conn = sasql_connect( $con_str ); if( ! $conn ) { echo "sasql_connect failed\n"; echo "</html>\n"; return 0; } $qname = str_replace( "\\", "", $qname ); $result = sasql_query( $conn, $qname ); if( ! $result ) { echo "sasql_query failed!"; } else { // echo "query completed successfully\n"; sasql_result_all( $result, "border=1" ); sasql_free_result( $result ); } sasql_disconnect( $conn ); echo "</html>\n"; ?> |
This design could be extended to handle complex web forms by formulating customized SQL queries based on the values entered by the user.
Discuss this page in DocCommentXchange. Send feedback about this page using email. |
Copyright © 2009, iAnywhere Solutions, Inc. - SQL Anywhere 11.0.1 |