Installing pear php in ubuntu machine helps you to use existing libraries to make our development easy. In terminal, run the following command: [code] sudo apt-get install php-pear [/code]
Tag: PHP
Permanent link to this article: https://blog.openshell.in/2013/02/how-to-install-pear-php-in-ubuntu/
Jan 17
Loop mysql result set multiple times or twice in php
First we will select something from the database and loop through it like so: [php] $result = mysql_query("SELECT * FROM my_table"); while($row = mysql_fetch_assoc($result)) { // inside the loop } [/php] Problem: if you want to loop through the same result set again, you will get an error because the internal pointer is currently at …
Permanent link to this article: https://blog.openshell.in/2013/01/loop-mysql-result-set-multiple-times-or-twice-in-php/
Nov 14
How to find php exec() function run without error
Use the following method to trace exec() function in PHP. Syntax: [php] exec($command, $output, $return_value); [/php] example1: [php] $command = "ls"; exec($command, $output, $return_value); // $output will contains list of files as array. // $return_value will be zero. [/php] Output: Array ( [0] => File1.txt [1] => File2.txt ) 0 example2: [php] $command = "l2"; …
Permanent link to this article: https://blog.openshell.in/2012/11/how-to-find-php-exec-function-run-without-error/
Sep 22
Disable foreign key checks in MySQL
Disabling foreign key checks in MySQL is usefull when you are dealing with tables that use foreign keys (InnoDB engine). You can not delete (drop) multiple tables, a parent table or a child table until you disable foreign key checks four your current database. The sql command to disable foreign key checks is: [sql]SET FOREIGN_KEY_CHECKS …
Permanent link to this article: https://blog.openshell.in/2012/09/disable-foreign-key-checks-in-mysql/
Jul 26
Pass command line argument to PHP
The command line arguments are stored in an array in the $_SERVER variables called ‘argv’. Running the command “php index.php test1 test2” and then doing print_r($_SERVER[‘argv’]) would output this: [php] Array ( [0] => index.php [1] => test1 [2] => test2 ) [/php] You can also use $argv, It has return the same value. $argc …
Permanent link to this article: https://blog.openshell.in/2012/07/pass-command-line-argument-to-php/
Apr 15
YII Primary Key error
Error: Table “user” does not have a primary key. Solution: The crud command requires primary key to be defined in your tables. If you are working with legacy tables and can’t specify primary key, you can declare it in primaryKey() method of your model class. override method primaryKey in protected/models/User.php [php] public function primaryKey() { …
Permanent link to this article: https://blog.openshell.in/2012/04/yii-primary-key-error/
Apr 15
APC extension Enable in apache
To enable APC extension on Ubuntu, Use the following command sudo apt-get install php-apc To enalbe APC extension on Windows, 1) Go to http://downloads.php.net/pierre/ 2) Download php_apc-.zip 3) Copy php_apc.dll to /ext folder 4) In your php.ini, make sure you have: extension=php_apc.dll 5) Restart your server.
Permanent link to this article: https://blog.openshell.in/2012/04/apc-extension-enable-in-apache/
Sep 23
PHP characters limitation
Characters limitation will helps to display limited number of characters to display. [php] function limit_characters( $str, $n ) { if ( strlen ( $str ) <= $n ) { return $str; } else { return substr ( $str, 0, $n ) . ‘…’; } } [/php]
Permanent link to this article: https://blog.openshell.in/2011/09/php-characters-limitation/
Sep 20
PHP Automatic Session Logout
Automatic logout script if users have inactive more than 15 minutes [php] <?php session_start(); $inactive = 900; // Set timeout period in seconds if (isset($_SESSION[‘timeout’])) { $session_life = time() – $_SESSION[‘timeout’]; if ($session_life > $inactive) { session_destroy(); header("Location: logoutpage.php"); } } $_SESSION[‘timeout’] = time(); ?> [/php]
Permanent link to this article: https://blog.openshell.in/2011/09/php-automatic-session-logout/
Sep 19
PHP MYSQL ORDER BY Multiple Columns
If you want to Order 2 or more columns in SQL Query. When ordering by more than one column, the second column is only used if the values are identical with the onces in the first column. Example [sql] ‘Order by Column ORDER BY COLUMN1, COLUMN2 [/sql] Order 2 or more columns with different orders …
Permanent link to this article: https://blog.openshell.in/2011/09/php-mysql-order-by-multiple-columns/