Thursday, 30 November 2017

MySQL Intro




1. WHAT IS DATABASE ?


A database is a separate application that stores a collection of data. Each database has one or more distinct APIs for creating, accessing, managing, searching and replicating the data it holds.
Other kinds of data stores can also be used, such as files on the file system or large hash tables in memory but data fetching and writing would not be so fast and easy with those type of systems.
Nowadays, we use relational database management systems (RDBMS) to store and manage huge volume of data. This is called relational database because all the data is stored into different tables and relations are established using primary keys or other keys known as Foreign Keys.

2. MYSQL DATABASE 
MySQL is a fast, easy-to-use RDBMS being used for many small and big businesses. MySQL is developed, marketed and supported by MySQL AB, which is a Swedish company. 

3. WHY MYSQL IS SO POPULAR? 
  • - MySQL is released under an open-source license. So you have nothing to pay to use it.
  • - MySQL is a very powerful program in its own right. It handles a large subset of the functionality of the most expensive and powerful database packages.
  • - MySQL uses a standard form of the well-known SQL data language.
  • - MySQL works on many operating systems and with many languages including PHP, PERL, C, C++, JAVA, etc.
  • - MySQL works very quickly and works well even with large data sets.
  • - MySQL is very friendly to PHP, the most appreciated language for web development.
  • - MySQL supports large databases, up to 50 million rows or more in a table. The default file size limit for a table is 4GB, but you can increase this (if your operating system can handle it) to a theoretical limit of 8 million terabytes (TB).
  • - MySQL is customizable. The open-source GPL license allows programmers to modify the - MySQL software to fit their own specific environments.

Tuesday, 14 November 2017

PHP

1. The PHP echo Statement

The echo statement can be used with or without parentheses: echo or echo().

Example (from w3 schools) :

<?php
echo "<h2>PHP is Fun!</h2>";
echo "Hello world!<br>";
echo "I'm about to learn PHP!<br>";
echo "This ", "string ", "was ", "made ", "with multiple parameters.";
?>



Step :
1. Open xampp control panel and start apache
2. Open dreamweaver
3. Paste the code from w3schools
4. Save file to local disk c - xampp - htdocs - dashboard
5. Put the filename as php1.php
6. Open the browser and open localhost 
7. Put the filename in the link : http://localhost/dashboard/php1.php
 
Output :




*If we stop the apache, the server will stop and page cannot be displayed. 

Open with folder

step :

1. Open file local disk c - xampp - htdocs - dashboard - php1.php
2. Right click on the file
3. Open with browser (ex : mozilla firefox)

Output :




View page source : 




2.PHP 5 Arrays

 

Loop Through an Indexed Array

Example :
<?php
$cars = array("Volvo", "BMW", "Toyota");
$arrlength = count($cars);

for($x = 0; $x < $arrlength; $x++) {
    echo $cars[$x];
    echo "<br>";
}
?>
Output : 
 Add coding on example :

<?php
$cars = array("Volvo", "BMW", "Toyota");
$arrlength = count($cars);

for($x = 0; $x < $arrlength; $x++) {
    echo $cars[$x];
    echo " x=.$x arrlength=.$arrlength";
    echo "<br>";
}
?>

Output :




  3. PHP FUNCTIONS

PHP Default Argument Value

 

Example : 

 

<?php
function setHeight($minheight = 50) {
    echo "The height is : $minheight <br>";
}

setHeight(350);
setHeight(); // will use the default value of 50setHeight(135);
setHeight(80);
?>
 
FILENAME : php3.php 
Output :
*setHeight();. No value is set, so it will use the default value that is 50.  
Default value statement : function setHeight($minheight = 50)
 

 

4. PHP 5 Form Handling

A Simple HTML Form

1. create html file 

<html>
<body>

<form action="welcome.php" method="post">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
<input type="submit">
</form>

</body>
</html>
 
FILENAME : form.html
 
Output : 
 
 
 
 
 
2. create php file
 
<html>
<body>

Welcome <?php echo $_POST["name"]; ?><br>
Your email address is: <?php echo $_POST["email"]; ?>

</body>
</html>  

FILENAME : welcome_get.php