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
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
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…)
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.
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…)
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);
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__;
}
}
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…)
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.
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.
Mysql Tips for Beginners
* How to log into Mysql from command prompt?
First, Go to the Mysql installation directory and move to the bin directory (C:\Mysql\bin\)
Execute the following command to log into Mysql
C:\Mysql\bin> mysql -u [username] -p [password]
You will be shown mysql command which indicates that you have successfully logged in
mysql> _
(more…)