PHP Classes

Classes do not use scope keywords, but you can prevent people from instantiating the class by making
the __construct() method and the __clone() methods private or protected. The __construct()
method is used to create the object so if it is not accessible, the object cannot be created. You don’t need
a __construct() method in your class to create an object, but if there is a __construct() method
then it needs to be available. So if you don’t need a __construct() method but don’t want people to


Checking Variable Values and Types

FUNCTION
is_numeric() True if number or numeric string
ctype_digit() True if all digits are numeric characters
is_bool() True if variable is a Boolean
is_null() True if variable is NULL
is_float() True if variable type is a fl oat
is_double() True if variable type is a double
is_int() True if variable type is integer
is_string() True if variable type is string
is_object() True if variable is an object
is_array() True if variable is an array


<?php
$b = 3;
$c = 0;
$d = ‘0’;
$e = ‘xyz3’;
if ($c != 0) {
echo $b/$c . ‘<br />’;
} else {
echo ‘Cannot divide by 0. <br />’;
}
echo ($c != 0) ? $b/$c : ‘Cannot divide by 0.<br />’;
echo ($d != 0) ? $b/$d : ‘Cannot divide by 0.<br />’;
echo ($e != 0) ? $b/$e : ‘Cannot divide by 0.<br />’;
?>

If you have display_errors on, the
user sees the error message. If you are logging errors, it is logged. You can use the E_USER_NOTICE
level to post informational notices that do not affect the processing, E_USER_WARNING level for
errors that allow processing to continue, or E_USER_ERROR to stop the processing.

function overloading?

Function overloading is defined as a normal function, but it has the ability to perform different tasks. It allows creation of several methods with the same name which differ from each other by type of input and output of the function.
Example
void add(int& k, int& s);
void add(double& k, double& s);
void add(struct bob& k, struct bob& s);

friend function?

Friend declaration can be placed anywhere in the class declaration.
Friend function that is a "friend" of a given class is allowed access to public, private, or protected data in that class.

default access specifier in a class definition?

Private access specifier is used in a class definition.

Difference between class and an object?

An object is an instance of a class. Objects hold any information , but classes don’t have any information. Definition of properties and functions can be done at class and can be used by the object.

Restore database (or database table) from backup?

 [mysql dir]/bin/mysql -u username -ppassword databasename < /tmp/databasename.sql

How set a root password if there is on root password?

# mysqladmin -u root password newpassword

total number of rows?

mysql> SELECT COUNT(*) FROM table;

Show unique records mysql?

mysql> SELECT DISTINCT column FROM table;