Kurinchi Blogger Scribbles …


Archive for February, 2009

Feb 25
2009

CentOS – Command to find the version

Last updated: March 25th, 2009

How to find the version of CentOS running in your machine?

The following commands can be executed to find the version of CentOS running in your machine.

Command 1:
# cat /etc/issue

Command 2:
# cat /etc/redhat-release

Feb 22
2009

MySQL – What is Character set and Collation?

Last updated: February 24th, 2009

As given by MySQL documentation (http://dev.mysql.com/doc/refman/4.1/en/charset-general.html): A character set is a set of symbols and encodings. A collation is a set of rules for comparing characters in a character set.

Why is MySQL Collation an important consideration?
Collation determines the rules in comparing characters including the case sensitiveness, accent sensitiveness, trailing space sensitiveness of the character set. (more…)

Feb 17
2009

PHP: final Methods, final Class

Last updated: February 15th, 2009

final Methods:

When you want an inheriting class NOT to define the method from its parent class, you will use the final Method.

class parentClass{
function methodA(){
echo “a”;
}
final function methodB(){
echo “b”;
}
}
// Following produces an error as it is trying to define a final method from its parent class
class childClass extends parentClass{
function methodB(){
echo “bbb”;
}
}

final Class:
When you do not want a class to be inherited, then you declare the class to be a final class.

Feb 16
2009

PHP5 – Being Static

Last updated: February 14th, 2009

Class properties

This is another name for properties (or methods) declared static inside classes as these properties belong to a class and not to any instance/object.

The keyword ‘static’ is used to define static properties. (more…)

Feb 15
2009

PHP4 Vs. PHP5 – What is New in PHP5? – Part 1

Last updated: May 21st, 2009

In PHP5, Zend engine has been rewritten to accomodate the new object oriented concepts. To start with, I will write on some functions that have been added to PHP5′s bag.

~ The access modifiers public/private/protected are introduced for methods and properties.

~ __construct() is used now instead of the function names in the name of the classes which makes it a uniform way of access

~ __destruct() function is now introduced which will run when an object is destroyed

Let us create a class to verify how the above concepts work.

class myBook{
 private var $bookTitle;
 function __constructor(){
     echo "Book object created in constructor";
  }
  function getBookTitle(){
      return $this->bookTitle;
   }
   function setBookTitle(){
      $this->bookTitle = "Hope Wins";
   }
   function __destruct(){
      echo "Object perishes now!";
   }
}
$myNewBook = new myBook();
// $myNewBook->bookTitle = "Truth about life";
// The above statement will return an error notice as the variable bookTitle declare private.
$myNewBook->getBookTitle();
$myNewBook = nothing;
unset($myNewBook);

~ Introduction of Abstract classes
An abstract class is a class that cannot be instantiated. But, you can inherit from an abstract class. If you want to declare a method as an abstract method, then you need to declare the class as an abstract class as well. When a method is declared abstract, then the inherting class will implement the method.

abstract class shape{

var $a, $b;

function calcSqFeet($a=0, $b=0){

if(!empty($a) && !empty($b){ echo "Square feet ".$a * $b); }

}

abstract function color();
}

class rectangle extends shape{
var $a, $b;

function __construct($a, $b){
$this->a = $a;
$this->b = $b;
}

function color(){
echo "Color of the shape is :" . "Red";
}

function getSqFeet($a, $b){
return calcSqFeet($a, $b);
}

}

// Declaration
$myShape->color();
$myShape->getSqFeet(3, 4);
Feb 15
2009

PHP: How to print a name of a class?

Last updated: May 21st, 2009

The following code helps identifying the name of the class with the usage of PHP constant __CLASS__

class myClass{

    function __construct(){
        echo "You are now inside class = ".__CLASS__;
    }

}
Feb 14
2009

Object Handling in PHP4, PHP5

Last updated: February 14th, 2009

In PHP4, objects are passed by value and in PHP5 objects are passed by reference.

A sample program is shown below to get a better idea on this topic. (more…)

Feb 13
2009

MySql Tip for Beginners – Import records from .csv from Command line

Last updated: February 12th, 2009

Importing a .CSV file in MySQL from command line.

When you want to import records from a .csv file into a table, follow the steps given below:

[root@localhost]$ mysql -u [username] -p [password]

[root@localhost]$ use [my_database]

[root@localhost]$ LOAD DATA LOCAL INFILE ‘userinfo.csv’ INTO TABLE [table name] FIELDS TERMINATED BY ‘,’ LINES TERMINATED BY ‘\n’;

This should be the same command that get executed on windows command prompt as well.

Feb 12
2009

MySql Tip for Beginners – Export records to .csv from Command line

Last updated: February 12th, 2009

Exporting a .CSV file based on user requirement is very easy in MySQL.

A simple query could generate your desired output as .CSV file. Let’s see what that command is

[root@localhost]$ mysql -u [username] -p [password]

[root@localhost]$ use [my_database]

[root@localhost]$ SELECT * INTO OUTFILE ‘/userinfo.csv’ FIELDS TERMINATED BY ‘,’ OPTIONALLY ENCLOSED BY ‘”" ESCAPED BY ‘\\’ LINES TERMINATED BY ‘\n’ FROM Table_Users;

Voila! You have your desired results in as a .csv file.

In the next article, we will discuss on how we can import data from .csv file back into database.


Valid HTML 4.01 Strict  Valid HTML 4.01 Strict