Kmysql-php is a PHP library permitting ultra-easy acces to KMySql forms via a browser, as standard HTML forms. Just three lines of PHP code are enough to provide full access to a form. A self-documented working example is also available in this package. For more information about KMySql, take a look at its web site.
Since KMySql 1.2.x forms work only with MySql servers, this library currently only works with MySql.
It will be integrated in the next version of KMySql (which is KSql 2.0), and since KSql will handle properly all database types, the ksql-php library will also do so.
<?php ... require("/path/to/kmysql.php3"); ... ?> |
Then you will have access to the following functions:
ksql_create_form(string host, string user, string passwd, string base, string form_name, string action) |
|
Parameters: | |
host |
The name of the DB server |
user |
A valid user name for the DB servere |
password |
The associated password |
base |
The name of the base containing the form you want to display |
form_name |
The name of the form you want to display |
action |
The URL that will be called when the form is submitted |
Returns | Nothing |
Description: | This function creates a complete HTML form corresponding to the kmysql form given by its name. This form has to be included in a complete HTML page. If an error occurs the function will die with the appropriate error message. |
ksql_run_form(string host, string user, string passwd, string base, array post_vars) |
|
Parameters: | |
host |
The name of the DB server |
user |
A valid user name for the DB servere |
password |
The associated password |
base |
The name of the base containing the form |
post_vars |
The variables transmitted using the POST method. In most cases you will pass the php variable $HTTP_POST_VARS here. Note that the PHP varaible php_track_vars must be set to use this variable. |
Returns | The result of the query generated by the form. See description for details. |
Description: | This function is used to treat the datas submitted via a form. It constructs the SQL query, sends
it to the server, and returns the result an associative array, containing the following elements:
|
ksql_print_result_to_table(array result) |
||
Parameters: | ||
result |
The result of a query as returned by ksql_run_form(). | |
Returns | Nothing | |
Description: | Prints out the result as an HTML table. The passed result must contains rows (type = 2 ).
|
ksql_print_result(array result) |
||
Parameters: | ||
result |
The result of a query as returned by ksql_run_form(). | |
Returns | Nothing | |
Description: | Prints out the result depending of its type. If the result contains arrays, this calls ksql_print_result_to_table(). Otherwise it prints a error or success message. |
We will create two PHP pages:
Here is the code for the first page: form.php3
.
<html> <body> <h1> Here is my form: </h1> <?php require("/path/to/kmysql.php3"); ksql_create_form("mysqlhost.mydomain.com", "bob", "xxxx", "my_base", "My form", "result.php3"); ?> </body> </html> |
Here is the code for the second page: result.php3
.
<html> <body> <h1> Here is the result: </h1> <?php require("/path/to/kmysql.php3"); $result = ksql_run_form("mysqlhost.mydomain.com", "bob", "xxxx", "my_base", $HTTP_POST_VARS); ksql_print_result($result); ?> </body> </html> |
That's all!