Showing posts with label cakephp. Show all posts
Showing posts with label cakephp. Show all posts

Sunday, March 20, 2011

Cakephp Store procedure + multiple resultset fetch

Hi All,


I have been working on a project which involves huge data. So the idea is to use stored procedures to make the query execution fast. Most tricky part in this, is to fetch multiple-result set from a single store procedure. 


Step 1: Write the procedure which have the multiple select queries.
Step 2 : Make a component within your cake's controller folder(app/controllers/components) and paste the code given below:

function callstoreproc($procname,$paramarr=null)
{
$connstr = ConnectionManager::getInstance();

$conhost = $connstr->config->default["host"];
$conlogin = $connstr->config->default["login"];
$conpassword = $connstr->config->default["password"];
$condatabase = $connstr->config->default["database"];

$mysqli = new mysqli($conhost, $conlogin, $conpassword, $condatabase);

if (mysqli_connect_errno())
{
echo "Connect failed";exit();
}
 $query = $procname;
 if (mysqli_multi_query($mysqli, $query))
{
$i=0;
while (mysqli_more_results($mysqli))
{
if ($result = mysqli_store_result($mysqli))
{

Saturday, February 19, 2011

Memcache with CakePHP

Hi,

Memcache simply means caching your query. This means that if you are caching your query then you do not need to make a database call every time. You need to run the database query once and set a refresh time. The next time, instead of the database the query will be fetched from the cache, thus improving the performance of the site. The refresh time is the frequency of refresing the content of the cache.

For achieving this you need to install memcache in the server. But CakePHP has a inbuilt caching system, which is similiar to conventional memcaching. Here I will discuss CakePHP's inbuilt memcaching system. In this you do not need to install memcache in your server.

Assuming you are using a model, Customer. The query you are using is: