Menus

Showing posts with label php. Show all posts
Showing posts with label php. Show all posts

Thursday 8 August 2019

Introduction to Codelgniter



Welcome to CodeIgniter



CodeIgniter is a powerful PHP framework with a very small footprint, built for developers who need a simple and elegant toolkit to create full-featured web applications.





Download

CodeIgniter is an Application Development Framework - a toolkit - for people who build web sites using PHP. Its goal is to enable you to develop projects much faster than you could if you were writing code from scratch, by providing a rich set of libraries for commonly needed tasks, as well as a simple interface and logical structure to access these libraries. CodeIgniter lets you creatively focus on your project by minimizing the amount of code needed for a given task.

Who is CodeIgniter For?

CodeIgniter is right for you if:
  • You want a framework with a small footprint.
  • You need exceptional performance.
  • You need broad compatibility with standard hosting accounts that run a variety of PHP versions and configurations.
  • You want a framework that requires nearly zero configuration.
  • You want a framework that does not require you to use the command line.
  • You want a framework that does not require you to adhere to restrictive coding rules.
  • You are not interested in large-scale monolithic libraries like PEAR.
  • You do not want to be forced to learn a templating language (although a template parser is optionally available if you desire one).
  • You eschew complexity, favoring simple solutions.
  • You need clear, thorough documentation.

Installation Instructions

Tutorial


Thursday 25 July 2019

how to get the number of days of the current month in PHP ?




cal_days_in_month — Return the number of days in a month for a given year and calendar

Description 

cal_days_in_month ( int $calendar , int $month , int $year ) : int
This function will return the number of days in the month of year for the specified calendar.
The length in days of the selected month in the given calendar

More details


example

             $m1=date('Y-m-d',strtotime($date_of_join));            
           
             $mon_num = date("m",strtotime($m1));
             $curr_year = date("Y",strtotime($m1));

            $num = cal_days_in_month(CAL_GREGORIAN, $mon_num, $curr_year);



PHP code for find number of days form given month and year ?



<?php

$month = 2;
$year = 2020;

$days = $month == 2 ? ($year % 4 ? 28 : ($year % 100 ? 29 : ($year % 400 ? 28 : 29))) : (($month - 1) % 7 % 2 ? 30 : 31);

echo $days;

?>




Thursday 20 December 2018

Calculating Age from Birthdate


Calculate age from given birthdate


How to Calculate Age from Date of Birth in PHP



<?php

$dateOfBirth = "21-12-1983";
$today = date("Y-m-d");
$diff = date_diff(date_create($dateOfBirth), date_create($today));
echo 'Age is '.$diff->format('%y');

?>




VB6 Code

Function Age (varBirthDate As Variant) As Integer 

 Dim varAge As Variant 

 If IsNull(varBirthdate) then Age = 0: Exit Function 

 varAge = DateDiff("yyyy", varBirthDate, Now) 
 If Date < DateSerial(Year(Now), Month(varBirthDate), _ 
 Day(varBirthDate)) Then 
 varAge = varAge - 1 
 End If 
 Age = CInt(varAge) 

 End Function





Tuesday 9 January 2018

PHP - MySQL - Connection


MySQL Connection Using PHP Script

PHP provides mysql_connect() function to open a database connection.

Syntax

connection mysql_connect(server,user,passwd,new_link,client_flag);


Returns a MySQL link identifier on success or FALSE on failure.


Example

<?php
         $dbhost = 'localhost';
         $dbuser = 'test';
         $dbpass = 'Ii@21!abg';
         $conn = mysql_connect($dbhost, $dbuser, $dbpass);
         if(! $conn ) {
            die('Could not connect: ' . mysql_error());
         }
         echo 'Connected successfully<br>';

         $sql = 'SELECT id, name, course FROM std';

         mysql_select_db('ellorahs_test');
         $retval = mysql_query( $sql, $conn );
   
         if(! $retval ) {
              die('Could not get data: ' . mysql_error());
         }
   
         while($row = mysql_fetch_array($retval, MYSQL_ASSOC)) {
            echo "ID :{$row['id']}  <br> ".
                 "Name : {$row['name']} <br> ".
                 "Course : {$row['course']} <br> ".
                 "--------------------------------<br>";
         } 
         echo "Fetched data successfully\n";

         mysql_close($conn);
?>


mysql_close()


Disconnect from the MySQL database anytime using another PHP function mysql_close().


SELECT command is used to fetch data from the MySQL database. 


Selecting a MySQL Database Using PHP

mysql_select_db to select a database. 
It returns TRUE on success or FALSE on failure.

Fetching Data Using a PHP


The SQL SELECT command is used to fetch data from the MySQL database.

SELECT command into a PHP function mysql_query().


mysql_fetch_array() can be used to fetch all the selected data.