Import a Controller in CakePHP

If you want to access some predefined controller in another controller in CakePHP. You can do this as explained in following example.

<?php
App::import('Controller', 'Events');
class HomesController extends AppController {
	var $name = 'Homes';
	var $Events;
	function beforeFilter() {
		$this->Events =& new EventsController();
		$this->Events->constructClasses();
	}
	function index() {
		$this->Events->index();
	}
}
?>

Model without Table in CakePHP

This is explained in following example

<?php
class ModelWithoutTable extends AppModel {
    var $useTable = false;
}
?>

Controller without Model in CakePHP

In some cases you may need to have a controller without its own model. This might be because you are using other models. You can do this by using an empty array.

<?php
class HomesController extends AppController {
	var $name = 'Homes';
	var $uses = array(); // Don't use Home Model
	function index() {

	}
}
?>

Connecting to mysql database

Below is the code for creating mysql connection in java and php.
Please make sure that mysql-connector-java-5.0.6-bin.jar is in class path.

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class MySqlConnectionTest {
    public static void main(String[] args) {
        Connection connection = null;

        try {
            Class.forName("com.mysql.jdbc.Driver").newInstance();
            // We want to connect to a database name 'test' in mysql.
            connection = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/test", "root", "root");

            if (!connection.isClosed()) {
                System.out.println("Successfully connected to MySQL server...");
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                if (connection != null) {
                    connection.close();
                }
           } catch (SQLException e) {
       }
    }
  }
}

Below is the code in php for mysql connection.

<?php
    $hostname='localhost'; //// specify host
    $user='root'; //// database user name
    $password='root'; //// database password
    $database='test'; //// database name
    $connection = mysql_connect("$hostname" , "$user" , "$passwprd")
    or die ("Unable connect to MySQL");
    $db = mysql_select_db($database , $connection) or die ("Can't find database.");
?>