mika

Mobile Enterprise Application Framework

Home
Screenshots
Download
Examples
Developer
Contact

Basic SQL Connect Example

TODO: This example is a fragment, must be completed.

These are the steps you have to do

  1. Setup mika server as done in our first example
  2. Setup demo application database
  3. Setup mika client and connect
  4. Modify the demo database and SQL query

All scripts for this demo are located in misc/demoSqlConnect.

Setup mika server

TODO

Setup the demo application database

cd /opt/mika/misc/demoSqlConnect
mysql -u root -p mika < mika-demo.sql

After installing the database, database 'backend' includes one table 'customers' which contains two demo recordsets. This data is shown on the smartphone finally.

Please adjust the connection settings to reach the mysql database 'backend' which was created before in file

lib/backends/BasicSqlConnect.php: $dbServer, $dbName, $dbUsername, $dbPassword

Setup mika client and connect

TODO

Modify demo database and SQL query

mysqladmin -u root -p create backend
mysql -u root -p < database-customers.sql
see ../INSTALL-CLIENT

Login to mika client (username: demo, password: demo). After login start Application SqlDemo.

Screenshot

Modify the demo database and SQL query

This is the data stored in our demo application database

mysql> select * from customers;
+----+-----------------+----------+---------------+
| ID | customerName    | address  | lastYearSales |
+----+-----------------+----------+---------------+
|  1 | Big Foo Company | New York |      12054.23 |
|  2 | Small Bar Ltd.  | Detroid  |       6143.52 |
+----+-----------------+----------+---------------+
2 rows in set (0.34 sec)

To customize the sql query go to bin/backends/BasicSqlConnect in line 111 and set the query to your backend table. Second you have to configure the output regarding to the selected table columns in line 123.

		switch ($view) {
			case "start":
[...]
			case "customers":
				$sql = 	'SELECT * ' .
					'FROM `customers` ' .
					'ORDER BY `customers`.`lastYearSales` DESC ' .
					'LIMIT 0 , 30';
				$this->mika->logger->logDebug("sql: " . $sql);
				$result = mysql_query($sql, $this->dbConnection);
				
				$data = array();
				while($row = mysql_fetch_assoc($result)) {
					$data = array_merge($data, array(
						array(
							"id" => 1,
							"text" => $row['customerName'] . ' | ' . $row['address'] . ' | ' . $row['lastYearSales'],
							"active" => 1
						)
					)); 
				}
[...]