Prabuforeducation.files.wordpress.com



PHPUNIT – 3 & 4Question Bank PART – A (2 Marks)What is an Array?An array is a data structure that stores one or more similar type of values in a single value. For example if you want to store 100 numbers then instead of defining 100 variables it’s easy to define an array of 100 lengths. Example:$cars1 = "Volvo";$cars2 = "BMW";$cars3 = "Toyota";Types of Arrays in PHPIndexed arrays?- Arrays with a numeric indexAssociative arrays?- Arrays with named keysMultidimensional arrays?- Arrays containing one or more array2.What is an Associative array?Associative array will have their index as string so that you can establish a strong association between key and values.There are two ways to create an associative array:$age = array("Peter"=>"35", "Ben"=>"37", "Joe"=>"43");or:$age['Peter'] = "35";$age['Ben'] = "37";$age['Joe'] = "43";3. What is an Indexed array?An indexed or numeric array stores each array element with a numeric index.The index can be assigned automatically (index always starts at 0), like this:$cars = array("Volvo", "BMW", "Toyota");orthe index can be assigned manually.$cars[0] = "Volvo";$cars[1] = "BMW";$cars[2] = "Toyota";4.What is the use of array_slice()?Give an example.The array_slice() function returns selected parts of an array.Syntax:array_slice(array,start,length,preserve)5. What is an array_chunck()?The array_chunk() function splits an array into chunks of new arrays.Syntax:array_chunk(array,size,preserve_key);6. How to identify element of an array.You can access specific values from an array using the array variable's name, followed by the element's key (sometimes called the?index) within square brackets:$age ['Fred']$shows [2]The key can be either a string or an integer.Example:Print "Hello, $person[name]";7. How to add values to the end of an array.To insert more values into the end of an existing indexed array, use the [] syntax: $family = array("Fred", "Wilma"); $family[] = "Pebbles"; // $family[2] is "Pebbles" Attempting to append to an associative array without appropriate keys is almost always a programmer mistake, but PHP will give the new elements numeric indices without issuing a warning: $person = array('name' => "Fred"); $person[] = "Wilma"; // $person[0] is now "Wilma"8.How to create objects.Once you defined your class, then you can create as many objects as you like of that class type. Following is an example of how to create object using new operator.$physics = new Books;$maths = new Books;$chemistry = new Books;9.Write a Query to display existing database names.Use the?SHOW?statement to find out what databases currently exist on the server:mysql>SHOW DATABASES;+----------+| Database |+----------+| mysql || test || tmp |+----------+10.Write a query to find the current data.The CURDATE() function returns the current date.The CURRENT_DATE() function is a synonym for the CURDATE() function.Syntax:CURDATE()11.Write a query to count the data givenCOUNT(HYPERLINK ""*)?counts the number of rows, so the query to count your animals looks like this:mysql>SELECT COUNT(*) FROM pet;Earlier, you retrieved the names of the people who owned pets. You can use?COUNT(HYPERLINK "")?if you want to find out how many pets each owner has:mysql>SELECT owner, COUNT(*) FROM pet GROUP BY owner;Number of animals per species:mysql>SELECT species, COUNT(*) FROM pet GROUP BY species;12.Write a query to load data into a table.To load the text file?pet.txt?into the?pet?table, use this statement:mysql>LOAD DATA LOCAL INFILE '/path/pet.txt' INTO TABLE pet;If you created the file on Windows with an editor that uses?\r\n?as a line terminator, you should use this statement instead:mysql>LOAD DATA LOCAL INFILE '/path/pet.txt' INTO TABLE petLINES TERMINATED BY '\r\n';13.How to create class.A classes can be declared using the class keyword,followed by the name of the classes and a pair of curly braces({})Example:?phpclassphpClass{var $var1;var $var2 = "constant string";functionmyfunc ($arg1, $arg2) { }}?>14.Write the syntax for InterfaceInterface InterfaceName{public function();}Then, if another class implemented that interface, like this ?class Report implements Mail { // sendMail() Definition goes here}15.Write a syntax for Inheritance.Syntax:class Child extends Parent {<definition body>}16.What is an abstract class?An abstract class is one that cannot be instantiated, only inherited. When inheriting from an abstract class, all methods marked abstract in the parent's class declaration must be defined by the child; additionally, these methods must be defined with the same visibility.abstract class MyAbstractClass{abstract function myAbstractFunction() { }}17.Write a query to insert data into a table.mysql>INSERT INTO petVALUES ('Puffball','Diane','hamster','f','1999-03-30',NULL);18.Write a query to update a table.The UPDATE statement is used to update existing records in a table:UPDATE table_nameSET column1=value, column2=value2,...WHERE some_column=some_value19.How to display particular columns.For example, if you want to know when your animals were born, select the?name?and?birth?columns:mysql>SELECT name, birth FROM pet;For example, to get birth dates for dogs and cats only, use this query:mysql>SELECT name, species, birth FROM petWHERE species = 'dog' OR species = 'cat';20.How to create new database.Create the database. From the MySQL command line, enter the command CREATE DATABASE <DATABASENAME>; . ...Display a list of your available databases. ...Select your database. ...Create a table. ...Create an entry in the table. ...Create more entries. ...Run a query on your new database.PART – B (16 Marks)1.Describe the creating object, accessing properties and methods, declaring a class, declaring a method and declaring properties.2.Explain the entire concept in sorting of an array in php.3.Explain the following with examplei) Splitting an array into chunks ii)Keys and Values iii)Slicing an array iv)Removing and Inserting Elements in an array4.Write MYSQL commands for the following operations with examples.Create a Database, Create a table, Load data into the table, Retrieve data from the table in various ways5. What are the ways followed in matching patterns using MYSQL statement?6.How to effectively use select statement for retrieving values in MYSQL.7.Write query and sample outputs for the following:i) Selecting all data ii) Selecting particular rowsiii)Selecting particular columns iv)Sorting rows ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download