Archive for the ‘ PHP ’ Category

Simple solution to complex where clause brace problen in Code-igniter


In Code-Igniter How do you make a query with where clause with a brace like following —

SELECT * FROM props 
WHERE `active` = 1
AND (rent >= 25 OR price >=25) AND 1=  1
AND `props`.`id` = '1'

Code-Igniter active record pattern does not generally support this type of query as far i searched.

I found a surprising solution for this type of query. for this query i make the where clause like following —

$this->db->where('(rent >= 25 OR price >=25) AND 1= ',1); 
$this->db->where('props.id',1); 

Which does the tricks.

I don’t actually know this is the fault of the developers or a feature but it is good for my work to move on.

so the total query for this SQL becomes —

$this->db->where('(rent >= 25 OR price >=25) AND 1= ',1); 
$this->db->where('props.id',1); 
$this->db->get('props');

cheers………

Simple solution to complex where clause brace problen in Code-igniter


In Code-Igniter How do you make a query with where clause with a brace like following —

SELECT * FROM props 
WHERE `active` = 1
AND (rent >= 25 OR price >=25) AND 1=  1
AND `props`.`id` = '1'

Code-Igniter active record pattern does not generally support this type of query as far i searched.

I found a surprising solution for this type of query. for this query i make the where clause like following —

$this->db->where('(rent >= 25 OR price >=25) AND 1= ',1); 
$this->db->where('props.id',1); 

Which does the tricks.

I don’t actually know this is the fault of the developers or a feature but it is good for my work to move on.

so the total query for this SQL becomes —

$this->db->where('(rent >= 25 OR price >=25) AND 1= ',1); 
$this->db->where('props.id',1); 
$this->db->get('props');

cheers………

Changing default apache page on Ubuntu


Open your Apache configuration file httpd.conf

on ubuntu it is in /etc/apache2/httpd.conf and open it using

sudo gedit /etc/apache2/httpd.conf

then put your desired filename on directory index—

DirectoryIndex index.html index.htm default.htm index.php index.pl

Changing default apache page on Ubuntu

Open your Apache configuration file httpd.conf

on ubuntu it is in /etc/apache2/httpd.conf and open it using

sudo gedit /etc/apache2/httpd.conf

then put your desired filename on directory index—

DirectoryIndex index.html index.htm default.htm index.php index.pl

Changing English date format to Bangla date format


i use here the following function to change English date format to Bangla date format when displaying —-


<?php
function getBanglaDate($date){
 $engArray = array(
 1,2,3,4,5,6,7,8,9,0,
 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December',
 'am', 'pm'
 );
 $bangArray = array(
 '১','২','৩','৪','৫','৬','৭','৮','৯','০',
 'জানুয়ারি', 'ফেব্রুয়ারি', 'মার্চ', 'এপ্রিল', 'মে', 'জুন', 'জুলাই', 'আগস্ট', 'সেপ্টেম্বর', 'অক্টোবর', 'নভেম্বর', 'ডিসেম্বর',
 'সকাল', 'দুপুর'
 );

 $converted = str_replace($engArray, $bangArray, $date);
 return $converted;
}

?>

calling procedure is like —


<?php

 if($GLOBALS['lang'] == "bn"){
 $date = date( 'j F, Y, a g:i',strtotime($publisheddate) ) ;
 $date = getBanglaDate($date);
 }else if($GLOBALS['lang'] == "en"){
 $date = date( 'j F, Y, g:i a',strtotime($publisheddate) ) ;
 }
 ?>

So when if send a date format like  “28 July, 2010, 12:00 am”  then it returns   “২৮ জুলাই, ২০১০, সকাল ১২:০০”    date format

Cheers………

Simple steps to setting up virtual host host on Ubuntu Server


Virtual host is a virtual environment over the top of your current web server to simulate a separate hosting environment. Using virtual host you can enable site specific features and keep your development environment totally separate from another one.

For tutorial you need to mod_rewrite enabled.

Step 1: setup hosts file

open /etc/hosts and add a virtual domain with a specific local IP.

Lets assume that our virtual domain name is “ruzdi.com” and It will listen to the ip “127.0.0.2″

so on /etc/hosts file we will add

127.0.0.2 ruzdi.com

now whenever you browse http://ruzdi.com your browser will actually hit http://127.0.0.2

Step2: configure virtual host with apache
Now goto /etc/apache2/sites-available and create a file named “ruzdi.com

sudo touch ruzdi
sudo gedit /etc/apache2/sites-available/ruzdi

write the following contents inside. but please note to create the appropriate directory before linking your virtual host with that, for example we’ve create a folder named “/var/opt/ruzdi” and linked that directory as my document root in the following configuration file.



<VirtualHost 127.0.0.2:80>
        ServerName  ruzdi.com
        ServerAlias  ruzdi.com
        ServerAdmin admin@ruzdi.com
        DocumentRoot /opt/ruzdi
        <Directory /opt/ruzdi/>
                Options FollowSymLinks
                AllowOverride All
        </Directory>

</VirtualHost>

now create a symbolic link of this file to /etc/apache2/sites-enabled directory as “ruzdi.com

sudo ln -s /etc/apache2/sites-available/ruzdi /etc/apache2/sites-enabled/ruzdi

**** here look directory location is /opt/ruzdi so you must create a directory named “ruzdi” on /opt location

Step 3: restart apache

simple, either one of the followings

sudo a2ensite ruzdi

And

sudo /etc/init.d/apache2 restart

now on your browser to http:// ruzdi.com

***This is post is similar Hasin Hyder blog post I just change a little. In my case on the hosts file port was not working so I removed it and I got everything all right.

source :

Apache

Hasin Hyder

Setting up zend framework on ubuntu server


Now i am going to install the Zend Framework. Download the most recent version from the Zend Framework website and extract it to the /opt folder.

To enable us to easily switch out different versions, we will create a symbolic link to this folder (just right click and select the ‘Make link’ option and name it ‘zend’ and place it to your favourite location in my case I placed it to /var/www/ )

Next, we will tell php to include the zend framework in the include_path.


sudo gedit /etc/php5/apache2/php.ini

Add/Change the include_path in to :


include_path = ".:/var/www/zend/library"

Note that I used the symbolic link in the include path.. This way, when there is a new version of ZF, we can just switch out the symlink without having to edit the ini file!

In order to use the zend framework command line tool (/var/www/zend/bin/zf.sh), we need to install the php command line interface (php5-cli).


sudo apt-get install php5-cli

Note that the CLI uses a different version of the php.ini file (NOT the one in the apache2 folder but in the cli folder!). We need to tell CLI also where the zend framework directory is located.


sudo gedit /etc/php5/cli/php.ini

and set:


include_path = ".:/var/www/zend/library"

The final step is to include the path to /opt/Zend/bin in the unix PATH variable (this way, you can use zf.sh instead of /var/www/ zend/bin/zf.sh). use the following command .

sudo gedit ~/.bashrc

Add the following line at the end:


PATH=/var/www/zend/bin:”${PATH}”

The Zend Framework relies on the apache “rewrite” module. So, go ahead and enable the “rewrite” module using the following command:


sudo a2enmod rewrite

Restart apache..


sudo /etc/init.d/apache2 restart

and you should be all set

Simple steps to Installing Xdebug on Ubuntu Server


First install pear


sudo apt-get install php5-dev php-pear

Now install xdebug thru PECL.


sudo pecl install xdebug

Now we need to find where xdebug.so went (the compiled module)


find / -name 'xdebug.so' 2> /dev/null /usr/lib/php5/20090626/xdebug.so

20090626 is for my case it might be different for you

Then edit php.ini


sudo gedit /etc/php5/apache2/php.ini

Add the following line:


zend_extension="/usr/lib/php5/20090626/xdebug.so"

Then restart apache


sudo /etc/init.d/apache2 restart

for changes to take effect.


sudo /etc/init.d/apache2 restart

For checking it is install or not —

create a file on /var/www/  as info.php

and open it

sudo gedit /var/www/info.php

and write —

<?php
phpinfo();
?>

Now we call that file in a browser (e.g. http://localhost/info.php):

Xdebug Test

Xdebug Test

Cheers ………