Sunteți pe pagina 1din 20

PHP Notes Intro

What is PHP?

PHP: Hypertext Preprocessor server-side HTML-embedded scripting language PHP is a server-side scripting language, like ASP ,executed on the server

all functions/commands are enclosed by start (<?php) and end tags (?>) start and end tags can be different . PHP is an open source software (OSS) database support dBase mSQL MySQL Oracle PostgreSQL (*) dbm

Why PHP?

PHP runs on different platforms (Windows, Linux, Unix, etc.) PHP is compatible with almost all servers used today (Apache, IIS, etc.) PHP is FREE to download from the official PHP resource: www.php.net PHP is easy to learn and runs efficiently on the server side

Syntax function calls have flexible syntax statements are terminated by a semicolon (;) or a PHP end tag (?>) supports C, C++, and Bourne Shell comments Types PHP supports: integer floating-point numbers string object

array

What Is a Constant? A constant is an identifier for a data value. Once defined, the data value identified by a constant can not be changed. PHP supports constants with following basic rules: 1. A constant must be defined with the define(name, value). For example, define("PI", 3.14159); defines a constant named as PI to a value of 3.14159. 2. To retrieve the value defined in a constant, you can use the constant name directly in any expression. For example, define("PI", 3.14159); $area = PI * $radius * $radius; uses the value define in PI to calculate the area. What is a variable? A variable is an identifier for a piece of data stored in memory during the program execution. In PHP, variables are used under these basic rules: 1. A variable name in PHP must be prefixed with a "$" sign. Perl has a similar rule for scale variables. 2. Variable names are case sensitive. So $address and $Address refer to two different variables. 3. Variables in PHP are typeless. Therefor there is no variable type declaration statements in PHP. Any variable can be used as the identifier for any data type. 4. A variable has 2 states: "set" and "unset". A variable is in the "set" state, if a piece of data has been assigned to it. A variable is in the "unset" state, if there is no data assigned to it. 5. Assignment operations (coded by the assignment operator, =) can be used to assign data to variables. 6.The unset($var) function can be used to remove the assigned data from the given variable.

Operations,type conversion,expressions:

PHP supports 6 basic types of operations: bitwise, arithmetic, comparison, logical, string, and assignment operations. PHP performs automatic type conversion, if an operand has a data type that does match the operator. Write your expressions properly with operand data types match operators to avoid automatic type conversion.

A)What Is an Expression? Giving a precise single definition of an expression is not an easy task. So I will try to define it in a recursive way: 1. A simple expression is a presentation of a data value like, a literal, a variable, an element of an array, or a function call. 2. A complex expression is a presentation of a data value returned from an operation represented by an operator, and one or two expressions as operands. The operation will result a new data value.

B)What Is an Operation? An operation is a process that takes one or two operands and returns a result based on certain processing rule represented by the operator. PHP supports most types of operations used in other programming languages: 1. Bitwise Operations: and ($a & $b), or ($a | $b), xor ($a ^ $b), not (~ $a), shift left ($a << $s), and shift right ($a >> $s). 2. Incrementing/Decrementing Operations: pre-increment (++$a), post-increment ($a++), pre-decrement (--$a), and post-decrement ($a--). 3. Arithmetic Operations: negation (-$a), addition ($a + $b), subtraction ($a - $b), multiplication ($a * $b), division ($a / $b), and modulus ($a % $b). 4. Comparison Operations: equal ($a == $b), identical ($a === $b), not equal ($a != $b, $a <> $b), not identical ($a !== $b), less than ($a < $b), greater than ($a > $b), less than or equal ($a <= $b), and greater than or equal ($a >= $b). 5. Logical Operations: and ($a and $b, $a && $b), or ($a or $b, $a || $b), xor ($a xor $b), and not (!$a). 6. String Operation: concatenation ($a . %b). 7. Assignment Operations: assignment ($a = %b), addition with assignment ($a += $b), subtraction with assignment ($a -= $b), multiplication with assignment ($a *= $b), division with assignment ($a /= $b), modulus with assignment ($a %= $b), and concatenation with assignment ($a .= %b). C)Precedence of Operations This section provides the order of precedence for operations commonly used in PHP. Operations in a complex expression must be evaluated according to the order of operation precedence. The following table shows you the relative order of precedence for some commonly used operations:
Precedence 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 Operations Notes (...) Operation group ++ -Increment/decrement ~ Unary negation ! Logical not * / % Multiplication, Division, ... + Addition and Subtraction . String concatenation << >> Bitwise shift < > <= >= Comparisons == != <> === !== Comparisons & Bitwise and ^ Bitwise xor | Bitwise or && And Logical and xor Logical xor || Or Logical or = += -= ... Assignments

Remember that:

Operations with higher precedence values must be evaluated first. Operations of the same precedence value must be evaluated from left to right.

D)Data Type Automatic Conversion This section provides rules on how operands are converted to data types required by the operation. PHP always finds a way to convert data from any type to any other type. When the PHP evaluating an operation, it will automatically convert the data type of an operand if it does not match the data type required by the operator. Here are some basic data type automatic conversion rules:

For logical operations, NULL, 0, or "" will be converted to FALSE. Any strings that can be parsed to 0 will also be converted to FALSE. Other values will be converted to TRUE. For arithmetic operations, strings will be parsed into numeric values. TRUE will be converted to 1. FALSE will be converted to 0. For comparison operations, if one operand is a numeric value, the other operand will be converted to a numeric value for a numeric comparison. If both operands are strings, it will be a string comparison. For string operations, NULL will be converted to "". TRUE will be converted to "1". FALSE will be converted to "". Numeric values will be converted to decimal presentations.

E)Conditional statements: E1)"if" Statements There are 4 forms of "If" statements supported in PHP: 1. Single-statement "if":
if (condition) statement

where "condition" is a Boolean value, and "statement" specify another statement. The specified statement will be executed, if and only if the specified condition is evaluated to "TRUE". 2. Multi-statement "if":
if (condition) { statement; statement; ... }

The specified multi-statement block will be executed, if and only if the specified condition is evaluated to "TRUE". 3. "if ... else" Statement:
if (condition) { statement; statement; ... } else { statement; statement; ... }

Two statement blocks are specified. But only one statement block will be executed based on the value of the specified condition. If the specified condition is "TRUE", the first block will be executed. If the specified condition is "FALSE", the second block will be executed. 4. "if ... elseif" Statement:
if (condition_1) { statement; statement; ... } elseif (condition_2) { statement; statement; ... } elseif (condition_3) { statement; statement; ... ... } else { statement; statement; ... }

E2)"switch" Statements "switch" statement is an alternative way of executing statements selectively based on certain conditions. Here is the syntax of "switch" statements:
switch (test_expression) { case expected_value_1: statement_block_1; break; case expected_value_2: statement_block_2; break; ... default: last_statement_block; }

where "test_expression" is an expression used to test against with expected values specified in "case" clauses, and "expected_value_*" are expected values. The execution of a "switch" statement goes like this:

Each "case" clause will be visited sequentially from top to bottom. If the result of the test expression matches the expected value in a "case" clause, the statement block in that clause will be executed. One a statement block is executed, all remaining statement blocks will also be executed. If no "case" clause is executed, the "default" clause will be executed. To stop executing remaining statements, you can use the "break" statement.

F)Loops: F1)"while" Statements The "while" statement is the most commonly used loop statement in PHP. There are 3 forms of

"while" statements supported in PHP: 1. Single-statement "while":


while (condition) statement;

2. Multi-statement "while":
while (condition) { statement; statement; ... }

3. Multi-statement "while ... endwhile":


while (condition): statement; statement; ... endwhile;

All forms of "while" statements are executed like this: Step 1: Evaluate "condition" as a Boolean value. Step 2: If "condition" returns TRUE, continue with Step 4. Step 3: If "condition" returns "FALSE", terminate the loop. Step 4: Execute the statement or statements enclosed in the loop. Step 5: Continue with Step 1. Of course, you can use the "break" statement inside the loop to terminate the loop immediately. F2)"for" Statements: The "for" statement is the most complex loop statement in PHP. There are 4 forms of "while" statements supported in PHP: 1. Empty-statement "for":
for (initial_exepression; stop_condition; repeating_expression);

2. Single-statement "for":
for (initial_exepression; stop_condition; repeating_expression) statement;

3. Multi-statement "for":
for (initial_exepression; stop_condition; repeating_expression) { statement; statement; ... }

4. Multi-statement "for ... endfor":


for (initial_exepression; stop_condition; repeating_expression): statement; statement; ...

endfor;

All forms of "for" statements are executed like this: Step 1: "initial_exepression" is evaluated unconditionally. The "initial_exepression" is usually used to assign the initial value to a loop control variable, like $i=0. Step 2: Evaluate "stop_condition" as a Boolean value. The "stop_condition" is usually a comparison expression against the loop control variable, like $i<100. Step 3: If "stop_condition" returns TRUE, continue with Step 5. Step 4: If "stop_condition" returns "FALSE", terminate the loop. Step 5: Execute the statement or statements enclosed in the loop. Step 6: Evaluate "repeating_expression". The "repeating_expression" is usually an expression to increment the value of the loop control variable, like $i++. Step 7: Continue with Step 2. F3)"do ... while" Statements PHP also supports a variation of the "while" statement called "do ... while" statement. with 2 forms: 1. Single-statement "do ... while":
do statement while (condition);

2. Multi-statement "do ... while":


do { statement; statement; ... } while (condition);

All forms of "do ... while" statements are executed like this: Step 1: Execute the statement or statements enclosed in the loop. Step 2: Evaluate "condition" as a Boolean value. Step 3: If "condition" returns TRUE, continue with Step 1. Step 4: If "condition" returns "FALSE", terminate the loop. Of course, you can use the "break" statement inside the loop to terminate the loop immediately. G)"break" and "continue" Statements In order to help us control the execution flow better, PHP provides two special statements, "break" and "continue", for statement blocks: 1. "break" statement with no option: It breaks the current statement block and the current loop where the "break" statement is located. The remaining statements in the current statement block will not be executed. If current statement block is running as a loop, the loop will also be terminated.
any_block { ... any_block { ... any_block {

... ...

... break; ... } } }

2. "break" statement with an option of integer, n: It breaks statement blocks and loops n levels backward. The remaining statements in all n levels of statement blocks will not be executed. If any of those statement blocks are loops, those loops will also be terminated.
any_block { ... any_block { ... any_block { ... break n; ... } } }

3. "continue" statement with no option: It breaks the current statement block and continues on the next iteration of the current loop where the "continue" statement is located. The remaining statements in the current statement block will not be executed. But the loop will continue on the next iteration, if current statement block is running as a loop.
any_block { ... any_block { ... any_block { ... continue; ... } ... } ... }

4. "continue" statement with an option of integer n: It breaks statement blocks and loops n levels backward. The remaining statements in all n levels of statement blocks will not be executed. But the n-th level loop will be continued on the next iteration, if the n-th level statement block is running as a loop.
any_block { ... any_block { ... any_block { ... continue n; ... } ... } ...

H)"function" Statements A "function" statement defines a function with the following syntax:
function function_name($argument_1, $argument_2, ...) { statement_1; statement_2; ... }

where "function_name" is the name of the function, and "$argument_1, $argument_2, ..." is a list of variables acting as arguments of the function. "statement_1; statement_2; ..." is a block of statements that becomes the body of the function. The "function_name" is the identifier of the function, it must follow PHP identifier naming conventions. The general rule is that don't use any special characters in function names. The argument list is optional. If not needed, define your function with no arguments but keep the argument parentheses like this:
function function_name() { statement_1; statement_2; ... }

When a function is called in an expression, it will always return a value for the expression. The returning value can be controlled in 3 ways: 1. If the function body is executed to the last statement without hitting any "return" statement, the default value, NULL, will be returned to the calling expression. 2. If an empty "return" statement is reached during the function body execution, the remaining part of the function body will not be executed and the default value, NULL, will be returned to the calling expression. 3. If a "return" statement with an expression, like "return expression", is reached during the function body execution, the remaining part of the function body will not be executed and the resulting value of the specified expression will be returned to the calling expression. I)What Is an Array? An array is a data type that represents an ordered pairs of keys and values. Arrays in PHP are different than arrays in most of other languages. Basic rules for PHP's arrays are: 1. An array can be constructed by the array constructor, like:
$myArray = array(k1=>v1, k2=>v2, ..., kn=>vn);

where k1, k2, ..., and kn are keys of integer type or string type. v1, v2, ..., and vn are values of any data types. 2. The value of a given key in an array can be expressed by the array variable followed by the key in square brackets, like:
print $myArray[kn];

3. The value of a given key in an array can be modified by an assignment statement, like:
$myArray[kn] = new_value.

4. A new pair of key and value can be added to an array by an assignment statement, like:
$myArray[kx] = vx

5. If a string key represents an integer, it will be used as an integer key. So $myArray['7'] is the same as $myArray[7]. 6. If the key is missing in an array assignment or an array constructor, an integer key of 0, or the highest integer key plus 1, will be provided. So $myArray[] = "Last" assigns "Last" to a new integer key. 7. An empty string is also a valid string key, like:
$myArray[''] = vy;

8. A pair of key and value can be removed by using the unset() function, like:
unset($myArray[kn]);

9. Pairs of keys and values are ordered in an array like a queue. New pairs are always added at the end of the array. I1)Array Related Built-in Functions PHP offers a number of interesting built-in functions to work with arrays:

array_combine() - Combines two arrays into a new array with the first array as keys and the second as values. array_count_values() - Counts the frequencies of values in an array and returns them as an array. array_key_exists() - Searches for a key in an array. array_keys() - Returns an array with all keys of an array. array_search() - Searches for a value in an array. array_values() - Returns an array with all values of an array. array_push() - Treats the array like a stack and pushes extra values to the end of the stack. array_pop() - Treats the array like a stack and pops the last value from the stack. ksort() - Sorts an array by keys. sort() - Sorts an array by values.

J)Retrieving Information from HTTP Requests KTopics include retrieving information from $_GET, $_POST, $_COOKIE, $_REQUEST, $_SERVER; promoting and registering $_REQUEST keys and values as global variables. Predefined Variables Related to HTTP Requests Operating System Information in $_SERVER Web Server Information in $_SERVER Information in $_GET and $_REQUEST Registering $_REQUEST Keys as Global Variables Conclusion:

$_GET contains information submitted with the GET method. $_POST contains information submitted with the POST method. $_COOKIE contains information stored as cookies. $_REQUEST is the sum of $_GET, $_POST, and $_COOKIE. $_SERVER contains information from the HTTP request, the Web server and the operating system.

K)What Is a Session? A session is an abstract concept to represent a series of HTTP requests and responses exchanged between a specific Web browser and a specific Web server. The session concept is very useful for Web based applications to pass and share information from one Web page (request) to another Web page (request). Since the current design of HTTP protocol does not support session concept, all Web server side scripting technologies, including PHP, have designed their own ways to support the session concept. The key design element of session support is about how to identify a session with an ID (identification) and how to maintain the session ID. One common way to maintain the session ID is use the cookie technology K1)How Sessions Are Support in PHP? This section describes how sessions are supported in PHP. Session IDs are passed as cookies or GET/POST variables. session_start() is the built-in function to start a session. $_SESSION is the built-in array to manage session data. PHP supports Web sessions with following main elements: 1. session.use_cookies = 1/0 - A setting in the configuration file, php.ini, to determine if the session ID should be stored and managed as a cookie. session.use_cookies = 1 (the default setting) - Managing the session ID as a cookie. The session ID is stored in a cookie with a default name of "PHPSESSID". This "PHPSESSID" cookie will be automatically inserted into HTTP responses and retrieved from HTTP requests by the PHP engine. session.use_cookies = 0 - Stop storing the session ID as a cookie.

2. session.use_trans_sid = 1/0 - A setting in the configuration file, php.ini, to control if the session ID should be stored and managed transparently as a parameter in the URL. session.use_trans_sid = 1 - Managing the session ID as an extra transparent parameter in the URL. The extra URL parameter contains the session ID value with a default name of "PHPSESSID". This "PHPSESSID" parameter will be automatically inserted into all links in the HTTP response, and retrived from HTTP requests by the PHP engine. session.use_trans_sid = 0 (the default setting) - Stop storing the session ID as a URL transparent parameter.

3. session.save_handler = files/mm/user - A setting in the configuration file, php.ini, to control how session data should be stored. session.save_handler = files (the default setting) - Storing session data as files in a directory defined in the session.save_path = "/tmp" setting. session.save_handler = mm - Storing session data in shared memory. session.save_handler = user - Storing session data through user-defined functions.

4. session_start() - A built-in function to create a new session or resume an existing session. When session_start() is called, the PHP engine will check the current HTTP request to see if an existing session ID is included or not. If no session ID is found, the PHP engine will create a new session with a new session ID. If a session ID is found, the PHP engine will restore the session identified by this session ID. If the restored session has been timed out, an error will be issued.

5. $_SESSION - A built-in array attached to the current session acting as a storage. You can store any number of key-value pairs in $_SESSION in a PHP script and retrieve them later in another script if it shares the same session as the first script. 6. session_name() - A built-in function to set and get the name of the current session. 7. session_id() - A built-in function to set and get the session ID of the current session. 8. session_destroy() - A built-in function to destroy the current session. When the current session is destroyed, information stored in $_SESSION will be removed. L)What Is a Cookie? A cookie is a piece of information sent by a Web server to a Web browser, saved by the browser, and sent back to the server later. Cookies are transmitted inside the HTTP header. Cookies move from server to browser and back to server as shown in the following diagram:
Web Server Web Browser Local System Web Browser Web Server

Send Receive Save Send back Receive cookies --> cookies --> cookies --> cookies --> cookies

As you can see from the diagram, cookies are actually saved by the local system in memory or on the hard disk of Web browser user's machines. Many users are concerned about this. But I think it is pretty safe to allow your browser to save cookies. If you are really concerned, you can change your browser's settings to reject cookies. But this may cause many Web based applications fail to run on your browser. M)MySQL Server Connection and Access Functions This chapter provides tutorial examples and notes about MySQL server connection with PHP. Topics include configuring the PHP engine to use the MySQL extension library, commonly used MySQL functions, running SQL statements to create table, insert rows and fetch rows. Configuring PHP for MySQL Server Access mysql_connect() and Other MySQL Functions MySqlLoop.php - MySQL Functions Test Conclusion:

PHP supports MySQL through an extension library, php_mysql.dll. Configuring the PHP engine to work with a MySQL server is simple - just turn on the extension=php_mysql.dll in php.ini. A database connection resource must be created with the mysql_connect() function. You can execute any SQL statements using the mysql_query() function.

M1)mysql_connect() and Other MySQL Functions This section describes functions supported by the MySQL extension library, php_mysql.dll. mysql_connect() creates a connection to the specified MySQL server. PHP's MySQL support comes from an extension library, php_mysql.dll, which offers a number of functions:

mysql_connect() - Connects to a MySQL server, and returns a connection resource. In most cases, you need to call it with 3 arguments like mysql_connect($server, $username, $password). $server specifies the network address of machine where the MySQL server is running. $username specifies the user login name on the MySQL server. $password specifies the password for the login name. mysql_close() - Closes a MySQL connection resource. Usually, you call it with 1 parameter like mysql_close($connection), where $connection represents the connection resource to be closed. mysql_get_server_info() - Returns a string of server information. mysql_status() - Returns a string of server status. mysql_query() - Sends a query to the server, and returns a result set resource. For example, mysql_query('SELECT * FROM MyTable WHERE ID = 10'). mysql_affected_rows() - Returns the number of effected rows of the given result set, if the executed query is an INSERT or UPDATE statement. mysql_num_rows() - Returns the number of rows of the given result set, if the executed query is a SELECT statement. mysql_fetch_array() - Fetches a row from a given result set, and returns the row as an array with both numeric index, and column name map. It will return boolean false, if there is no row left in the result set. mysql_free_result() - Frees the given result set.

N)Functions to Manage Directories, Files and Images This chapter provides tutorial examples and notes about functions to manage directories, files, and images. Topics include directory management functions like mkdir(), file testing functions like is_file(), file input and output functions like fopen(), image file management functions like imagecreatefromgif(). opendir() and Directory Management Functions file_exists() and File Testing Functions FileExistsTest.php - File Testing Examples fopen() and File Input/Output Functions File_Input_Output_Test.php - File Input/Output Examples readfile() and Special File Handling Functions imagecreatetruecolor() and GD Imaging Library Functions ShowPhoto.php - Simple Slid Show Script Conclusion:

PHP supports directory management functions similar to Unix commands like chdir(), mkdir() and rmdir().

To navigate through the directory tree, you can use opendir() and is_dir() functions. To obtain detailed information about a file, you can use the stat() function. To read data from a file, you can use fopen() and fread() functions. To write data to a file, you can use fopen() and fwrite() functions. To read image from a GIF file, you can use the imagecreatefromgif() function.

Q1.Can we write windows like applications in PHP. Ans : Yes using PHP-GTK on linux and WinBinder on windows. Q2.What difference does it make when I declare variables with $ and $ in prefix. Ans: $x = "Lion"; $$x = "Zebra"; echo $Lion; would display "Zebra" Use : creating runtime variables Q3.What is the difference between strpos and stripos function? Ans: strpos is case sensitive search, and stripos is case insensitive search Q4.What are the ways by which we can find out if a variable has been declared? Ans: isset or empty language constructs Q5.What is "global" and how to use it? Ans: variables declared outside the functions can be used inside the function using global keyword Q6.What is the difference between echo and print Ans: echo can take more than one parameter for displaying. print cannot take more than one e.g echo 'This', 'That' //is valid print 'This', 'That' //is invalid print returns 1 always. echo cannot be used to return anything $ret = print "Abcd" //valid $ret = echo "Abcd" //invalid Q7.What are predefined variables in php, give some examples. Ans: PHP provides an additional set of predefined arrays containing variables from the web server (if applicable), the environment, and user input. These new arrays are rather special in that they are automatically global [ Resource Link : http://in.php.net/manual/en/language.variables.predefined.php ] e.g., $_SERVER, $_REQUEST, $_POST, $_GET, $_ENV, $_COOKIE, $_FILES, $_SESSION, $GLOBALS, $php_errormsg, $http_response_header Q8.Give examples of predefined classes in PHP, and specify the use of anyone of them. Ans: stdClass, Exception,_PHP_Incomplete_Class, php_user_filter, Directory Exception : for exception handling Directory: dir class Q9.Declaring a class. Ans: public/private/protected [static] class <classname> extends <baseclassname>{ public $x; public function method_a() { } } Q10.How can we instantiate a class with default values. Ans: Write a function with the same name as class and assign values to the vars. E.g.: class myclass { private $var1, $var2;

function myclass() { $this->var1 = "Demo"; $this->var2 = "Disabled"; } function __get($x) { return $this->$x; } } $m = new myclass(); echo $m->var1 . " Vars " . $m->var2; Q11.Abstraction, interfaces explain the main difference. Ans: a) Abstract classes cannot be instantiated, b) They start with keyword abstract before the class name, c) One can force the methods to be declared in the inheriting class by creating abstract functions d) only abstract class can have abstract methods eg. abstract class a { abstract function b(); public function c() { echo "Can be used as it is"; } } class m extends a { public function b() { echo "Defined function b"; } } $tClass = new m(); $tClass->b(); $tClass->c(); Q12.Interface classes only provide the skeleton of the class that the inheriting class must implement. Eg. interface Person{ public function myFunc(); } class Employee implements Person { public function myFunc() { echo "Implemented"; } } $tClass = new Employee(); $tClass->myFunc(); Q13.What are magic methods? Ans: Functionalities like serializing, converting objects to string, getting setting values without explicit get and set methods for the variables etc, are magic functionality. PHP defines methods with names starting with __(double underscore). Eg. __get, __set, __construct, __destruct, __set, __isset, __unset, __sleep, __wakeup, __toString, __clone, __autoload, __set_state [ Resource Link : http://in.php.net/manual/en/language.oop5.magic.php ]

Q14.What does function `eval` do? Ans: Evaluate a string as PHP code; Eg. eval('echo "This would be printed"'); Q15.What is the method by which PHP converts datatype of a given variable. Ans: settype() $a = "10"; // $a is string settype($a,"integer"); // $a is integer Q.Can we change php.ini settings at the runtime, and how? Ans : Yes, using ini_set(); Q16.What is the difference between sort(), assort() and ksort? Under what circumstances would you use each of these? Ans: Sorts an array, sorts an array and maintains index association, Sorts an array by key Simple sort (sorts on values) Simple sort after sorting the array (lets assume size of array is 10) rearranges the index, if we want to access element at index[5], using a simple sort an element value would have changed, but in assort the value is still held by index 5 though its position in the array may be 10th. Ksort sorts the array by key and maintains the key to data correlations Q17.What is the difference between foo() & @foo()? Ans: if an error occurs calling foo() would show up the error on the screen, whereas, @foo() would suppress the error because @ is a error control operator. Q18.What is the difference between mysql_fetch_row() and mysql_fetch_array() and mysql_fetch_object? Ans: mysql_fetch_row() fetches a row as an enumerated array mysql_fetch_array() - Fetch a result row as an associative array, a numeric array, or both mysql_fetch_object - Fetch a result row as an object Q19.What is the difference between include & include_once? include & require? Ans: include_once includes the script only once if it is already included in the execution of the script Include includes the script everytime the include is encountered in the code Require is identical to include except that it results in fatal error when file is not present in the include_path. Q20.What type of inheritance PHP supports? Ans: An object can inherit only from one base class. Multiple inheritance is not supported in PHP. Q21.How can we call an object's method by using the variable functions? Ans: If MyClass contains function myFunction() $foo = new MyClass(); $var = "myFunction"; $c->$var(); [ Resource Link : http://in.php.net/manual/en/functions.variable-functions.php ] Ajax, Cross site scripting (JavaScript). Q22.What is the use of AJAX? Ans: If a page contains form that needs to be updated constantly based on runtime values, a javascript code constantly sends user input to the system and displays the results from the server, without refreshing the whole page. Q23.What is cross site scripting, and how to avoid it? Ans: Injecting a javascript code in the response of a form that is capable of calling and executing scripts from other site. Occurs when variables holding form values are not cleaned with html code escaping functions. Clean the variables before storing or before display. Recommendation is to display the code clean and store the value as it is, unless its specified otherwise. MYSQL. Q1.What is a join, what types of join are supported in MySQL. Ans: A join joins two table in such a way that all or partial records are selected from both the table based on join criteria. Joins supported in mysql are : [INNER | CROSS] JOIN

STRAIGHT_JOIN LEFT [OUTER] JOIN NATURAL [LEFT [OUTER]] JOIN RIGHT [OUTER] JOIN NATURAL [RIGHT [OUTER]] JOIN Q2.In MySQL, what table type is required for foreign keys to work? Ans: innoDB Q3.How does full text search work. Ans: A table must be a myISAM table Table must have char varchar and text columns FULLTEXT index must be created at the time of creation of table Q4.What is the use of files .frm, .MYD, .MYI Ans: frm files store the table definition MYD files store the data MYI files store the index Q5.What is maximum size of a database in MySQL? Ans: 65+GB / table / [ limited by the OS] Q6.How many columns can exist in a mySql table? Ans: 4096 colums Q7.What is the maximum size of a row in a mysql table? Ans: 65,535 not including blobs (as these are stored separately) Q8. What would you use if you have a choice Natural [left] join or inner join or left join with using clause? Ans: The NATURAL [LEFT] JOIN of two tables is defined to be semantically equivalent to an INNER JOIN or a LEFT JOIN with a USING clause that names all columns that exist in both tables Introduction to PHP & Mysql From Static to Dynamic Websites What is PHP? What is MySQL? Where to get PHP and MySQL? The Big Picture: How PHP and MySQL fit the Web PHP Fundamentals PHP.ini Configuration File Basic Syntax Mixing PHP and HTML About Comments Quick Start for Programmers PHP Language Overview Variables, Datatypes, Operators Escaping Special Characters Strings Numbers String Manipulations String Concatenation, Upper/Lower Case, Sub Strings, Replacement String Formatting with printf Conditionals If Statement Switch Statement

Loops For Loop While Loop Foreach Loop Loop Control (break and continue) Nested Loops Functions Function Definition Function Scope Arguments and Return Values Arrays What Are Arrays (definition) Indexing by Number Indexing by Strings - Associative Arrays Arrays and Loops Form Processing Review of HTML Forms (check boxes, text fields, radio buttons) Retrieving Form Data The GET and POST method Submitting to Itself Validating User Input with Regular Expressions Intro to Regular Expression Metacharacters Verifying Email Addresses, ZIP code, Phone Numbers, Credit Cards PCRE Functions Files and Directories Read and Writing Files Working with Directories Working with CSV Files About File Permissions Introduction to MySQL Administration The Command-Line Client MySQL Control Center Connecting to Database Server Selecting a Database SQL Language The Big Picture: Databases, Tables, and Fields SELECT Statement INSERT, UPDATE, and DELETE Statement CREATing Databases PHP and MySQL Connecting from PHP to MySQL Executing SQL Queries Retrieving Query Results Putting It All Together

Sessions and Cookies Introduction to Sessions and Cookies Password-protecting Pages Objects in PHP Introduction to Objects Properties and Methods Introduction to PEAR Installing PEAR Overview of PEAR Library Debugging PHP Code About PHP Error Handling Using Print to Narrow Error Messages Advanced Topics PHP and Javascript PHP and Images PHP and PDF PHP and Flash PHP is Hypertext Preprocessor and also knows as Personal Home Page is a scripting language originally designed for producing dynamic web pages. PHP is a widely-used general-purpose scripting language that is especially suited for web development and can be embedded into HTML. It generally runs on a web server, taking PHP code as its input and creating web pages as output. It can be deployed on most web servers and on almost every operating system and platform free of charge. PHP is installed on more than 20 million websites and 1 million web servers. PHP is probably the most popular scripting language on the web. It is used to enhance web pages. With PHP, you can create username and password login pages, create forums, check details from a form, picture galleries, surveys, and a whole lot more. Since PHP websites run on Linux and Unix, PHP websites are considered more secure compared to Windows supported languages such as ASP and .NET. Unlike other programming languages, with PHP& Mysql a fresher can learn and develop websites in a span of 4-6 months. PHP & MySQL web hosting is much cheaper than Windows supported hosting. PHP applications are sturdier and can easily adapt to various web hosting environments. PHP & MySQL Certification does not require any License fees unlike Windows supported languages. PHP runs on Windows NT and many Unix versions, and it can be built as an Apache module and as a binary that can run as a CGI. When built as an Apache module, PHP is especially lightweight and speedy. Without any process creation overhead, it can return results quickly. What is MySQL? MySQL, the most popular Open Source SQL database management system, is developed, distributed, and supported by MySQL AB. MySal is a relational database management system (RDBMS). The program runs as a server providing multi-user access to a number of databases.

S-ar putea să vă placă și