Error Handling in PHP

php-training-in-gurgaon
Error handling is the process of catching errors from the program and then taking appropriate action. Before proceeding for error handling you should get to know how many types of errors occurred in PHP. Notices: These are non-critical errors that occurred while executing a script - for example, accessing a variable that has not yet been defined. By default, such errors are not displayed to the user at all - although, as you will see, you can change this default behavior. Warnings: These are more serious errors - for example, attempting to use a file (using include() method) which does not exist. By default, these errors are displayed to the user, but they do not result in script termination. Fatal Errors: These are critical errors - for example, creating an…
Read More

Require () and Include () function in PHP

php-training-in-gurgaon
The Include() and require() statements are used to insert codes written in other files, in the flow of  execution. The main of using include and require functions to integrate one page code or content into another page. You can maintain usually some repeated functionality in the form of PHP file and finally you can call it wherever you want. See, the following example demonstrates how to integrate a menu content in other pages of PHP. There is a page in menu.php and it can be included in some other pages of the website. Menu.php <a href=”index.php”>Home</a> <a href=”services.php”>Services</a> <a href=”about.php”>About Us</a> <a href=”contact.php”>Contact Us</a> The following page index.php uses above menu.php content. See the below code how it follows <head> <title>My Web page</title> </head> <body> <?php include  “menu.php “; ?> </body> Difference between Include…
Read More

Data types in Mysql / Mariadb

php-training-in-gurgaon
Numeric Data Types: INT (Integer): Int data type represents an integer of normal size. So simply it can used to store numeric value. There are also BIGINT, MEDIUMINT, SMALLINT and TINYINT which represent different range of integer values. DECIMAL: Decimal data type represents numbers with specific floating values. Maximum permitted value is 65 and maximum decimals are 30. There are also FLOAT and DOUBLE to store numeric values with floating point. BOOLEAN:  This data type associates a value 0 with ―”false”, and a value 1 with true. Date and Time Data Types:  DATE: The DATE data type represents a date in “YYYY-MM-DD” format. TIME: The TIME data type represents a time in "HH:MM:SS" format. DATETIME: The DATETIME data type represents date and time in “YYYY-MM-DD HH:MM:SS” format. TIMESTAMP: This data…
Read More

The do-while loop

php-training-in-gurgaon
Difference Between while and do…while Loop: With a while loop, the condition to be evaluated is tested at the beginning of each loop statement, so if the conditional expression evaluates to false, the loop will never be executed. With a do-while loop, on the other hand, the loop will always be executed once, even if the conditional expression is false, because the condition is evaluated at the end of the loop statement. Example: <?php $i = 1; do { $i++; echo  $i . "<br>"; } while($i <= 3); ?>  Output: 2 3 4
Read More

PHP -Building Blocks

php-training-in-gurgaon
If –else statements: if…else statement – executes set of codes if a condition is true and another code if the condition is false Within a statement, if a certain condition is true, then something happens. Otherwise, something else happens. We can continue adding else statements as many times as we need. So, within PHP statement, we first define the variable and then set up the conditional statements like this: Syntax: if (condition) code to be executed if condition is true; elseif (condition) code to be executed if condition is true; else code to be executed if condition is false; Example 1: <?php $avg = 50 if ($avg>60) { echo "You have a good score"; } else { echo "Score is less than average"; } ?> Example 2:  <?php $status =…
Read More

PHP Superglobals

php-training-in-gurgaon
We already learned about variables, but there are some Readymade or predefined keywords in PHP that can be used without you having to create them first. Predefined or Superglobals variables are used to provide information from and about the web server, the web browser, and the user. There are several types of Super Global Variables:- $_GET - Is used to pass data through URL. Example: http://websjyoti.com?id=2 $_POST - Is used to pass data to server by hiding from URL. $_REQUEST – Is the combination of $_GET, $_POST, and $_COOKIE. $_SESSION - is used to maintain session and data from Local machine to Server. $_COOKIE – Is used to save/get user data on same machine in browser cookies. $_SERVER – Is an associative array which is used to know server information…
Read More

PHP – Date / Time Functions

php-training-in-gurgaon
When working in any programming language, dealing with dates and time is a simple task. That is, until time zones have to be supported. PHP's time () function gives you all the information that you need about the current date and time. It requires no arguments but returns an numeric value. If you will call to time() function which will return a set of numeric values which is difficult to understand. So to make it easy we can have time format along with the date() function. <?php $today = date("d/m/Y"); echo "Today is ".$today; ?> We can use different time format with separator like d-m-Y, d.m.Y and so on. Display Current Date and Time:  We can use the following characters to format the time string: <?php echo date("h:i:s") . "<br>";…
Read More