Call Oracle (oci8) store procedure from Codeigniter

Codeigniter is a nice framework and it’s support for oci8 is promising. Being inspired I started a project with Codeigniter and Oracle. But on the fly I started facing some problems. When i call store procedure from Codeigniter it gives me error. And the major problem is binding.

Don’t know why but this function don’t work all time for store procedure parameters.

File system\database\drivers\oci8\oci8_driver.php


/**
* Bind parameters
*
* @access  private
* @return  none
*/
private function _bind_params($params)
{
    if ( ! is_array($params) OR ! is_resource($this->stmt_id))
    {
        return;
    }

    foreach ($params as $param)
    {
        foreach (array('name', 'value', 'type', 'length') as $val)
        {
            if ( ! isset($param[$val]))
            {
                $param[$val] = '';
            }
        }

        oci_bind_by_name($this->stmt_id, $param['name'], $param['value'], $param['length'], $param['type']);
    }
}

Then I decided to use php oci functions and it worked.

This way i did.


$params = array(
                array('name' => ':params1', 'value' => $params1_val, 'type' => SQLT_CHR, 'length' => 32),
array('name' => ':params2', 'value' => $params2_val, 'type' => SQLT_CHR, 'length' => 32),
array('name' => ':params3', 'value' => $params3_val, 'type' => SQLT_CHR, 'length' => 32)
);

$stmt = oci_parse($this->db->conn_id, "begin package.procedure_name(:params1, :params2, :params3); end;");

foreach($params as $p)
    oci_bind_by_name($stmt, $p['name'], $p['value'], $p['length']);
$r = ociexecute($stmt);

Here in my stored Procedure all parameters are VARCHAR2. So I used title = SQLT_CHR

Here you will find the list of all oci_bind_by_name types.

Codeigniter and .htaccess dynamic sub domain creation using URL rewrite

For a project I was trying to make dynamic sub domains for every user. I knew that it can be done by .htaccess mod_rewrite. But I didn’t know exactly how. Then I googled for solution and got a large number of tutorials. There I got some working tutorials too.

But the problem was, using those tutorials I can easily point a file like this:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

RewriteCond %{HTTP_HOST}  ^([^.]+)\.example\.com$
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com$
RewriteRule ^(.*)$ user.php?uid=%1 [L]

And also like this:

<IfModule mod_rewrite.c>
   Options +FollowSymLinks
   Options +Indexes
   RewriteEngine On
   RewriteBase /
   RewriteCond %{HTTP_HOST} !www.example.com$ [NC]
   RewriteCond %{REQUEST_URI} ^/$
   RewriteCond %{HTTP_HOST} ^(www.)?([a-z0-9-_]+).example.com [NC]
   RewriteRule (.*) /welcome/user/%2 [R]
</IfModule>

But these don’t work for Codeigniter. Second one work but change the browser URL. So this is a big problem. I tried removing [R]. But then no redirection.

Then I start reading mod_rewrite documentation. And finally realize that it is happening for a flag. You have to set flag [P]. It treat the URL as a proxy. So your URL in browser will not change. I am writing this article because when i searched there were not enough documentation to describe this problem simply.

Hope this will help you.

Final and Working Code:

<IfModule mod_rewrite.c>
   Options +FollowSymLinks
   Options +Indexes
   RewriteEngine On
   RewriteBase /

   RewriteCond %{HTTP_HOST} !www.example.com$ [NC]
   RewriteCond %{REQUEST_URI} ^/$
   RewriteCond %{HTTP_HOST} ^(www.)?([a-z0-9-_]+).example.com [NC]
   RewriteRule (.*) /index.php/controller/function/%2 [P]

   RewriteCond $1 !^(index\.php|images|robots\.txt|css|js)
   RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>