Category: PHP

In our PHP session you will learn about PHP, and how to execute scripts on your application

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"; …

Continue reading

Permanent link to this article: https://blog.openshell.in/2012/11/how-to-find-php-exec-function-run-without-error/

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 …

Continue reading

Permanent link to this article: https://blog.openshell.in/2012/09/disable-foreign-key-checks-in-mysql/

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 …

Continue reading

Permanent link to this article: https://blog.openshell.in/2012/07/pass-command-line-argument-to-php/

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() { …

Continue reading

Permanent link to this article: https://blog.openshell.in/2012/04/yii-primary-key-error/

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/

How To Install memcached with memcache PHP Extension on Ubuntu

memcached and the PHP5 memcache module are available as packages, so we can install them as follows: sudo apt-get install memcached php5-memcache

Permanent link to this article: https://blog.openshell.in/2012/04/how-to-install-memcached-with-memcache-php-extension-on-ubuntu/

Enable Sqlite in PHP on Apache

To enable SQLite on Windows/Apache/PHP setup, Uncomment the following lines in the php.ini file and restart Apache: [code] extension=php_pdo.dll extension=php_pdo_sqlite.dll [/code] To enable SQLite on Ubuntu, Use the following command [code] sudo apt-get install sqlite php5-sqlite sudo apt-get install php-pear php-apc php5-curl [/code]

Permanent link to this article: https://blog.openshell.in/2012/04/enable-sqlite-in-php-on-apache/

session-start – headers already sent

This happens when you try to start session more than once. [php] The solution for above problem is 1) in php.ini file set session.autostart to 0 session.auto_start = 0 2) Placing a .htaccess file in the root of your web directory with the following value: php_flag session.auto_start 0 3) In your code use this line …

Continue reading

Permanent link to this article: https://blog.openshell.in/2011/10/1263/

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/

Resize image in specified height & width while upload

Resizing images in specified height & width while uploading files to the server. [php] /* Create a thumbnail of $srcFile and save it to $destFile. The thumbnail will be $width pixels. */ function createThumbnail($srcFile, $destFile, $new_w, $new_h, $quality = 75) { $thumbnail = ”; if (file_exists($srcFile) && isset($destFile)) { $size = getimagesize($srcFile); $old_x = $size[0]; …

Continue reading

Permanent link to this article: https://blog.openshell.in/2011/09/resize-image-in-specified-height-width-while-upload/