PHP ZCE mock test, interview preparation, daily lessons under chalk talk

Sunday, March 17, 2013

Mysql - alter a table column to make it auto increment

Mysql : alter a table to make one of its column auto increment.


Query :




mysql> ALTER TABLE  WAREHOUSE MODIFY COLUMN WarehouseId INT(11) AUTO_INCREMENT;
ERROR 1075 (42000): Incorrect table definition; there can be only one auto column and it must be defined as a key



i.e. in order to define a column as auto increment it must be set as primary key.

mysql> ALTER TABLE  WAREHOUSE MODIFY COLUMN WarehouseId INT(11) AUTO_INCREMENT PRIMARY KEY;

Query OK, 0 rows affected (0.15 sec)
Records: 0  Duplicates: 0  Warnings: 0





Friday, March 15, 2013

PHP - find biggest number in a array where array can also have nested arrays

PHP -Write a program to find biggest number in an array where array can also have nested arrays.

For example given an array like
Input : (1, 0, 6, 9, array(100, -1, 10, 7), 40, array(101, array(120, 240), 180), 200)

that can contain numbers and nested arrays containing numbers, we need to return the maximum number.

Output : 240


Program:


<?php

$inputArray = array(1, 0, 6, 9, array(100, -1, 10, 7), 40, array(101, array(120, 240), 180), 200);
echo findBiggest($inputArray);

function findBiggest($inputArray)
{
        static $biggest = 0;
        if(is_array($inputArray))
        {
                foreach($inputArray as $arr)
                {
                        findBiggest($arr);
                }
        }
        else
        {
                if($inputArray > $biggest)
                        $biggest = $inputArray;
        }
        return $biggest;

}

Monday, June 11, 2012

How does MVC pattern work?

How does MVC pattern work?


MVC ie Model View Controller pattern is a methodology for separating the business
logic (model) from the display logic (view) and the decisional controls (controller).


When a User clicks on a URL say http://php-geeks-wink.blogspot.in/ below are the steps processed
1. Front Controller receives the request and sets up the environment.
2. Thereon request reaches the controller.
3. Controller interacts with Model to perform any db queries.
4. Control then reaches to View, preparing the response.
5. Response is then sent back to the browser.

Friday, January 20, 2012

Zend Certified Engineer PHP5.3 ZCE




I passed the ZCE exam on 24th dec, 2011. I would like to share my exam experience with you.
I went for exam at NIIT Ltd , Cannought Place, New Delhi. I already scheduled my exam via Pearson Vue.
At Exam Center, When I Informed that I have already scheduled my exam at 11AM, they were surprised!!! It seemed that usually people directly go to exam center without even scheduling.

For exam, I wasn't allowed to keep any blank paper or pen. They gave a writing board and a marking pen.
There were total 70 questions and time allotted was 90 minutes. Questions were of single choice, multiple-choice and open text questions. For multiple-choice questions , it was clearly mentioned on how many to choose. On choosing more answers it gave an alert. However, if you choose less, loss is all yours.

During the exam, Computer got switched off twice. As expected on restarting time counting started from where it was left.

I was done with the paper in about 50 minutes. Rest of the time I reviewed my answers. As per my review, out of 70 questions 48 were for sure correctly answered. Answer for 1 question was a blind guess. And for the rest of the question, I gave logical answers. In all I guess about 60 questions got correct. I was lucky enough to get the exam passed.

I have 2 years of experience of developing with PHP, and I believe that practical exposure is must in order to clear the exam. Exam wasn't about the theory part at all.

You must be clear about below types of questions before going to attemp

1)
function stringAppend($str)
{
$str = $str."append";
}
function stringPrepend($str)
{
$str = "prepend".$str;
}

$aString = "PHP";
echo stringPrepend(stringAppend($aString));

2)
function updateValue(&$number)
{
$number = $number +1;
}
$val = 9;
echo updateValue(&$val);


3)
$foo = 'charanjeet/working/with/php';
echo strrpos($foo, '/', -5);


4)
class MyException extends Exception { }
class Test {
        public function testing()
        {
                try
                {
                        try
                        {
                                throw new MyException('foo!');
                        }
                        catch (Exception $e)
                        {
                                echo 'cought1';
                                /* rethrow it */
                                throw $e;
                        }
                        catch (MyException $e)
                        {
                                echo 'cought2';
                                /* rethrow it */
                                throw $e;
                        }
                }
                catch (MyException $e)
                {
                        echo 'cought3';
                        echo $e->getMessage();
                }
        }
}

$foo = new Test;
$foo->testing();


5)
Which of the following are valid PHP variables?

1. @$foo
2. &$variable
3. ${0x0}
4. $variable
5. $0x0


6)What is the output of the following PHP code?
<?php
define('FOO', 10);
$array = array(10 => FOO,          
    "FOO" => 20);
print $array[$array[FOO]] * $array["FOO"];

7)

What is the output of the following PHP script?

<?php
$a = 1;
$b = 2.5;
$c = 0xFF;

$d = $b + $c;
$e = $d * $b;
$f = ($d + $e) % $a;

print ($f + $e);

?>
1. 643.75
2. 432
3. 643
4. 257
5. 432.75
Click here for answer

8)

What is the output of the following code?

<?php
$string = "111221";
for($i = 0; $i < strlen($string); $i++) {
 $current = $string[$i];
 $count = 1;
 while(isset($string[$i + $count]) && ($string[$i + $count] == $current)) $count++;
 $newstring .= "$count{$current}";
 $i += $count-1;
}

print $newstring;
?>
1. 312211
2. 3312212
3. 11221221
4. 221131
5. 3211122



9)

What is the best way to ensure that a user-defined function is always passed an object as its single parameter?


1. function myfunciton($a = stdClass)
2. Use is_object() within the function
3. There is no way to ensure the parameter will be an object
4. function myfunction(Object $a)


10)

function stringAppend(&$str)

{

return $str = $str."append";

}

function stringPrepend(&$str)

{

$str = "prepend".$str;

}


$aString = "PHP";

echo stringPrepend(stringAppend($aString));

Next parts would come soon!!!