Example:
[SQLConnect dbType=MySQL&host=192.168.1.1&database=SMSITest&uid=sa&pwd=pass&conn_var=conn1] Connected successfully
[/SQLConnect] [SQLExecute conn_ref=conn1&result_var=rs1] select firstName,lastName from employees; [/SQLExecute] [SQLResult result_ref=rs1] [numFound] records found
First Name | Last Name |
---|---|
[firstName] | [lastName] |
Parameter | Description |
---|---|
|
(Required) - The name of the SQLResult variable you created with a prior execution of [SQLExecute] (the value you set for the "result_var" or "var" parameter) |
The following tags are available inside a [SQLResult] context:
Tag | Description |
---|---|
[CommandText]
|
The SQL command string that was executed via the [SQLExecute] context. |
[NumFound]
|
A number indicating how many records were returned as the result of the SQL statemtnt (a 'select' staement in most cases). Some SQL statements will not result in a record set, i.e. DELETE, INSERT, DROP, etc... In these cases [numfound] will be zero. |
[NumFields]
|
A number indicating the number of fields in the returned record set. |
[NumRowsAffected]
|
The number of rows changed by an INSERT/UPDATE/DELETE command. |
[InsertID]
|
The insert ID of a successfull INSERT command. |
[FoundItems]...[/FoundItems]
|
Normally you put a [FoundItems] loop inside a [SQLResult] context to retrieve the records resulting from a SQL SELECT statement, so you can display all the matching records. You can put any record set field name inside the [FoundItems] loop to display them in HTML.
There are other SQL commands that will return a records set. For example, in MySQL, the following statements will return a record set:
"show tables;" "show processlist;" "describe <table>;" |
It may sometimes be the case when you will not know all or any of the field names returned in a record set.
Executing 'Select * from mytable' will pull all field values into the record set, but will you *know* what those field names are? If not, you can use the [ListFields] context to iterate the field names of a result set.
For example:
[SQLConnect dbType=MySQL&host=192.168.1.1&database=SMSITest&uid=sa&pwd=pass&conn_var=conn1] [/SQLConnect] [SQLExecute conn_ref=conn1&result_var=rs1] select * from employees; [/SQLExecute] [SQLResult result_ref=rs1] [numFound] records found
[fieldname] | [/ListFields]
---|
[interpret][[fieldname]][/interpret] | [/ListFields]
You can also use the new [Field], inside [FoundItems], to retrieve field data by the fields position in the records set.
For example:
[SQLConnect dbType=MySQL&host=192.168.1.1&database=SMSITest&uid=sa&pwd=pass&conn_var=conn1] [/SQLConnect] [SQLExecute conn_ref=conn1&result_var=rs1] select * from employees; [/SQLExecute] [SQLResult result_ref=rs1] [FoundItems] [loop start=1&end=[numFields]] [field seek=ordinal:[index]&get=NAME]: [field seek=ordinal:[index]&get=VALUE] [hideif [index]=[numfields]]- [/hideif] [/loop]
[/FoundItems] [/SQLResult]