01/12/2014

What is Database?

| |
0 comments

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 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 types of systems.

So 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.

A Relational DataBase Management System (RDBMS) is a software that:
  • Enables you to implement a database with tables, columns and indexes.
  • Guarantees the Referential Integrity between rows of various tables.
  • Updates the indexes automatically.
  • Interprets an SQL query and combines information from various tables.

RDBMS Terminology:

Before we proceed to explain MySQL database system, let's revise few definitions related to database.
  • Database: A database is a collection of tables, with related data.
  • Table: A table is a matrix with data. A table in a database looks like a simple spreadsheet.
  • Column: One column (data element) contains data of one and the same kind, for example the column postcode.
  • Row: A row (= tuple, entry or record) is a group of related data, for example the data of one subscription.
  • Redundancy: Storing data twice, redundantly to make the system faster.
  • Primary Key: A primary key is unique. A key value can not occur twice in one table. With a key, you can find at most one row.
  • Foreign Key: A foreign key is the linking pin between two tables.
  • Compound Key: A compound key (composite key) is a key that consists of multiple columns, because one column is not sufficiently unique.
  • Index: An index in a database resembles an index at the back of a book.
  • Referential Integrity: Referential Integrity makes sure that a foreign key value always points to an existing row.
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. MySQL is becoming so popular because of many good reasons:
  • 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.
Read More

MySQL Introduction

| |
0 comments

MySQL Introduction

MySQL is (as of July 2013) the world's most widely used open-source relational database management system (RDBMS), enabling the cost-effective delivery of reliable, high-performance and scalable Web-based and embedded database applications. It is widely-used as the database component of LAMP (Linux, Apache, MySQL, Perl/PHP/Python) web application software stack.

MySQL was developed by Michael Widenius and David Axmark in 1994. Presently MySQL is maintained by Oracle (formerly Sun, formerly MySQL AB).

MySQL tutorial of w3resource is a comprehensive tutorial to learn MySQL(5.6). We have hundreds of examples covered, often with PHP code. This helps you to learn how to create PHP-MySQL based web applications.

What is MySQL
  • MySQL is a database management system. 
  • MySQL databases are relational.
  • MySQL software is Open Source.
  • The MySQL Database Server is fast, reliable, scalable, and easy to use.
  • MySQL Server works in client/server or embedded systems.
  • Initial release : 23 May 1995Current stable release : 5.6.13 / 30 July 2013
  • Written in : C, C++
  • Operating system : Cross-platform
  • Available in : English
  • License of MySQL is available under GNU General Public License (version 2) or proprietary EULA.
  • MySQL reduces the Total Cost of Ownership (TCO)   
                     - Reducing database licensing costs by over 90%
                     - Cutting systems downtime by 60%
                     - Lowering hardware expenditure by 70%
                      -Reducing administration, engineering and support costs by up to 50% 

MySQL Editions

There are five types MySQL editions.
  • MySQL Enterprise Edition : This edition includes the most comprehensive set of advanced features, management tools and technical support to achieve the highest levels of MySQL scalability, security, reliability, and uptime. 
  • MySQL Standard Edition : This edition enables you to deliver high performance and scalable Online Transaction Processing (OLTP) applications. It provides the ease of use that has made MySQL famous along with industrial-strength performance and reliability.
  • MySQL Classic Edition : This edition is the ideal embedded database for ISVs, OEMs and VARs developing read-intensive applications using the MyISAM storage engine.
  • MySQL Cluster CGE : MySQL Cluster is a scalable, real-time, ACID-compliant database, combining 5 x 9s availability and open source technology. With a distributed, multi-master architecture and no single point of failure, MySQL Cluster scales horizontally on commodity hardware accessed via SQL and NoSQL APIs. 
  • MySQL Embedded (OEM/ISV) : MySQL Database is a full-featured, zero-administration database that more than 3000 ISVs, OEMs, and VARs rely on to bring their products to market faster and make them more competitive. 
 Who uses MySQL
  • Some of the most visited websites like Flickr, Facebook, Wikipedia, Google (not for search), YouTube. 
  • Content Management Systems like WordPress, phpBB, Drupal, Joomla, TYPO3, MODx.
  • Last but not least, a large number of web developers across the world.

MySQL supported platforms

MySQL runs on

    -Linux (RedHat, SUSE, Mandrake, Debian)
    -Embedded Linux (MontaVista, LynuxWorks BlueCat)
    -Unix (Solaris, HP-UX, AIX)
    -BSD (Mac OS X, FreeBSD)
    -Windows (Windows 2000, Windows NT)
    -RTOS (QNX)

MySQL supported third party tools

Drivers :

    -ODBC
    -JDBC
    -.NET
    -C++

Languages :

    C
    C++
    C#
    Java
    Delphi
    Visual Basic
    Perl
    Python
    PHP

Development Tools :

    Microsoft Visual Studio
    Borland Delphi and JBuilder
    Eclipse
    NetBeans
 
 Some of the widely used MySQL front ends (tools for managing MySQL)

The MySQL GUI Tools Bundle is a cross-platform open source suite of desktop applications, building and manipulating the data within MySQL databases Development on the GUI Tools bundle has stopped, The GUI Tools bundle has been replaced by MySQL Workbench with the beta releases of MySQL Workbench 5.2. Currently MySQL Workbench Team are working on Version 6.0. The first public beta, labeled version 6.0.2, was released on June 14, 2013.
There are lot of third-party free and proprietary graphical administration applications available that integrate with MySQL and users to work with database. Here are some third-party tools for managing

MySQL :

Tools                            Description
phpMyAdmin                Third party, Free, Web based
HeidiSQL                      Third party, Free, For Windows
Adminer                        Third party, Free
DBEdit                          Third party, Free
dbForge GUI Tools        Third party, Free
Navicat                          Third party, Commercial
Maatkit                           Third party, Command line, free
MySQL Sandbox           Third party, Command line, free
SQLBuddy                     A free Web-based front end, developed in PHP.
SQLyog                          Commercial, but a free 'community' edition is available.
Toad for MySQL            Third party, free from Quest Software

Key features of MySQL

    MySQL follows ANSI SQL 99, the standard SQL.
    Cross Platform.
    Unicode support
    ACID compliance
    Stored procedures
    Triggers
    Cursors
    Views
    Information schema
    Strict mode (ensures MySQL does not truncate or otherwise modify data to conform to an underlying data type, when an incompatible value is inserted into that type)
    Independent storage engines
    Transactions with the InnoDB and NDB Cluster storage engines; savepoints with InnoDB
    SSL support
    Query caching
    Sub-SELECTs (i.e. nested SELECTs)
    Replication support (i.e. Master-Master Replication & Master-Slave Replication) with one master per slave, many slaves per master
    Full-text indexing and searching using MyISAM engine
    Embedded database library
    Shared-nothing clustering through MySQL Cluster
    Support for hotbackup
    Multiple storage engines, allowing one to choose the one that is most effective for each table in the application
    Commit grouping, gathering multiple transactions from multiple connections together to increase the number of commits per second.

Key relational database features supported by MySQL

    High-performance
    Main-memory tables with disk-based tables
    Single-User and Multi-User
    Multi-Threaded
    Multi-Process
    SQL-92 and SQL-99
    ACID Transactions
    Referential Integrity
    Cascading Updates and Deletes
    Multi-table Joins
    Row-level Locking
    Online Hot Backup
    Replication
    Clustering
    BLOBs (Binary Large Objects)
    UDFs (User Defined Objects)
    OLTP (On-Line Transaction Processing)
    Unicode and Double-Byte character support
    Drivers for ODBC, JDBC, .NET and C++

Tutorial objectives

1. A short and concise description to help you to understand about the topic / MySQL command.

2. Syntax of the MySQL command with descriptions of all the parameters used.

3. Display of the actual table on which the MySQL command is being applied.

4. How that MySQL command can be executed with PHP.

5. Explanation of the code.

6. Output of the MySQL command when executed form windows command prompt.

7. Display of the output with PHP in a separate browser window.

8. After reading this largest third party online MySQL tutorial by w3resource, you will be able to install, manage and develop PHP-MySQL web applications by your own.

9. You may refer MySQL Documentation along with this tutorial.

We have a comprehensive, SQL TUTORIAL -2003 standard , which will help you to understand how to prepare queries to fetch data against various conditions.
MySQL :
Tools Description
phpMyAdmin Third party, Free, Web based
HeidiSQL Third party, Free, For Windows
Adminer Third party, Free
DBEdit Third party, Free
dbForge GUI Tools Third party, Free
Navicat Third party, Commercial
Maatkit Third party, Command line, free
MySQL Sandbox Third party, Command line, free
SQLBuddy A free Web-based front end, developed in PHP.
SQLyog Commercial, but a free 'community' edition is available.
Toad for MySQL Third party, free from Quest Software
- See more at: http://www.w3resource.com/mysql/mysql-tutorials.php#sthash.hzaVFuZW.dpuf
MySQL :
Tools Description
phpMyAdmin Third party, Free, Web based
HeidiSQL Third party, Free, For Windows
Adminer Third party, Free
DBEdit Third party, Free
dbForge GUI Tools Third party, Free
Navicat Third party, Commercial
Maatkit Third party, Command line, free
MySQL Sandbox Third party, Command line, free
SQLBuddy A free Web-based front end, developed in PHP.
SQLyog Commercial, but a free 'community' edition is available.
Toad for MySQL Third party, free from Quest Software
- See more at: http://www.w3resource.com/mysql/mysql-tutorials.php#sthash.hzaVFuZW.dpuf
MySQL :
Tools Description
phpMyAdmin Third party, Free, Web based
HeidiSQL Third party, Free, For Windows
Adminer Third party, Free
DBEdit Third party, Free
dbForge GUI Tools Third party, Free
Navicat Third party, Commercial
Maatkit Third party, Command line, free
MySQL Sandbox Third party, Command line, free
SQLBuddy A free Web-based front end, developed in PHP.
SQLyog Commercial, but a free 'community' edition is available.
Toad for MySQL Third party, free from Quest Software
- See more at: http://www.w3resource.com/mysql/mysql-tutorials.php#sthash.hzaVFuZW.dpuf
Read More

20/11/2014

PHP Installation

| |
0 comments

PHP Installation

What Do I Need?

To start using PHP, you can:
  • Find a web host with PHP and MySQL support
  • Install a web server on your own PC, and then install PHP and MySQL
Use a Web Host With PHP Support

If your server has activated support for PHP you do not need to do anything.

Just create some .php files, place them in your web directory, and the server will automatically parse them for you.

You do not need to compile anything or install any extra tools.

Because PHP is free, most web hosts offer PHP support.

Set Up PHP on Your Own PC

However, if your server does not support PHP, you must:
  • install a web server
  • install PHP
  • install a database, such as MySQL

The official PHP website (PHP.net) has installation instructions for PHP: http://php.net/manual/en/install.php

Tip: To get PHP up and running immediately for Windows, you can:
Download WebMatrix
Read More

19/11/2014

PHP Introduction

| |
0 comments

PHP Introduction

PHP scripts are executed on the server.

What You Should Already Know

Before you continue you should have a basic understanding of the following:
  • HTML
  • CSS
  • JavaScript

If you want to study these subjects first, find the tutorials on our Home page.

What is PHP?
  • PHP is an acronym for "PHP: Hypertext Preprocessor"
  • PHP is a widely-used, open source scripting language
  • PHP scripts are executed on the server
  • PHP is free to download and use
*PHP is an amazing and popular language!
    It is powerful enough to be at the core of the biggest blogging system on the web (WordPress)!
    It is deep enough to run the largest social network (Facebook)!
    It is also easy enough to be a beginner's first server side language!

What is a PHP File?
  • PHP files can contain text, HTML, CSS, JavaScript, and PHP code
  • PHP code are executed on the server, and the result is returned to the browser as plain HTML
  • PHP files have extension ".php"

What Can PHP Do?
  • PHP can generate dynamic page content
  • PHP can create, open, read, write, delete, and close files on the server
  • PHP can collect form data
  • PHP can send and receive cookies
  • PHP can add, delete, modify data in your database
  • PHP can be used to control user-access
  • PHP can encrypt data

With PHP you are not limited to output HTML. You can output images, PDF files, and even Flash movies. You can also output any text, such as XHTML and XML.

Why PHP?
  • PHP runs on various platforms (Windows, Linux, Unix, Mac OS X, etc.)
  • PHP is compatible with almost all servers used today (Apache, IIS, etc.)
  • PHP supports a wide range of databases
  • PHP is free. Download it from the official PHP resource: www.php.net
  • PHP is easy to learn and runs efficiently on the server side

Read More

18/11/2014

HTML Attributes

| |
1 comments

HTML Attributes

Attributes provide additional information about HTML elements.

HTML Attributes


    HTML elements can have attributes
    Attributes provide additional information about an element
    Attributes are always specified in the start tag
    Attributes come in name/value pairs like: name="value"

The lang Attribute


The document language can be declared in the <html> tag.

The language is declared in the lang attribute.

Declaring a language is important for accessibility applications (screen readers) and search engines:

Example: 

<!DOCTYPE html>
<html lang="en-US">
<body>

<h1>My First Heading</h1>

<p>My first paragraph.</p>

</body>
</html>
 The first two letters specify the language (en). If there is a dialect, use two more letters (US).

The title Attribute

HTML paragraphs are defined with the <p> tag.

In this example, the <p> element has a title attribute. The value of the attribute is "About FindingPHP":
<!DOCTYPE html>
<html>
<body>

<h1>About FindingPHP</h1>

<p title="About FindingPHP">
FindingPHP is a web developer's site.
It provides tutorials and references covering
many aspects of web programming,
including HTML, CSS, JavaScript, MySQL, DOM, PHP.
</p>

<p><b>
If you move the mouse over the paragraph above,
the title will display as a tooltip.
</b></p>

</body>
</html>
*When you move the mouse over the element, the title will be displayed as a tooltip.
Demo

The href Attribute

HTML links are defined with the <a> tag. The link address is specified in the href attribute:
<!DOCTYPE html>
<html>
<body>

<a href="http://findingphp.blogspot.in/">This is a link</a>

</body>
</html>
You will learn more about links and the <a> tag later in this tutorial.
Demo

Size Attributes

HTML images are defined with the <img> tag.
The filename of the source (src), and the size of the image (width and height) are all provided as attributes:
 
<!DOCTYPE html>
<html>
<body>

<img src="http://i.imgur.com/QdEj8Lf.jpg" width="100" height="100">

</body>
</html>

Demo
The image size is specified in pixels: width="100" means 100 screen pixels wide.

You will learn more about images and the <img> tag later in this tutorial.

The alt Attribute

The alt attribute specifies an alternative text to be used, when an HTML element cannot be displayed.

The value of the attribute can be read by "screen readers". This way, someone "listening" to the webpage, i.e. a blind person, can "hear" the element.
<!DOCTYPE html>
<html>
<body>

<img src="http://i.imgur.com/QdEj8Lf.jpg" alt="FindingPHP" width="100" height="100">

</body>
</html>
Demo
We Suggest: Always Use Lowercase Attributes

The HTML5 standard does not require lower case attribute names.

The title attribute can be written with upper or lower case like Title and/or TITLE.

W3C recommends lowercase in HTML4, and demands lowercase for stricter document types like XHTML.

*Lower case is the most common. Lower case is easier to type.
    At FindingPHP we always use lower case attribute names.

We Suggest: Always Quote Attribute Values

The HTML5 standard does not require quotes around attribute values.

The href attribute, demonstrated above, can be written as:
<!DOCTYPE html>
<html>
<body>

<a href=http://findingphp.blogspot.in/>This is a link</a>

</body>
</html>
Demo
W3C recommends quotes in HTML4, and demands quotes for stricter document types like XHTML.
Sometimes it is necessary to use quotes. This will not display correctly, because it contains a space:
 
<!DOCTYPE html>
<html>
<body>

<h1>About FindingPHP</h1>

<p title=About FindingPHP>
You cannot ommit qoutes around an attribute value
if the value contains spaces.
</p>

<p><b>
If you move the mouse over the paragraph above,
your browser will only display the first word from the title.
</b></p>

</body>
</html>
Demo
*Using quotes are the most common. Omitting quotes can produce errors.
    At FindingPHP we always use quotes around attribute values.

Single or Double Quotes?

Double style quotes are the most common in HTML, but single style can also be used.

In some situations, when the attribute value itself contains double quotes, it is necessary to use single quotes:
<p title='John "ShotGun" Nelson'>
Or vice versa:
<p title="John 'ShotGun' Nelson">

Chapter Summary

  • All HTML elements can have attributes
  • The HTML title attribute provides additional "tool-tip" information
  • The HTML href attribute provides address information for links
  • The HTML width and height attributes provide size information for images
  • The HTML alt attribute provides text for screen readers
  • At FindingPHP we always use lowercase HTML attribute names
  • At FindingPHP we always quote attributes with double quotes
Read More

HTML Elements

| |
0 comments

HTML Elements

HTML documents are made up by HTML elements.

HTML elements are written with a start tag, with an end tag, with the content in between:

<tagname>content</tagname>

The HTML element is everything from the start tag to the end tag:

<p>My first HTML paragraph.</p>

Start tag     Element content     End tag
<h1>          My First Heading     </h1>
<p>            My first paragraph.    </p>
<br>
*Some HTML elements do not have an end tag. 

Nested HTML Elements


HTML elements can be nested (elements can contain elements).

All HTML documents consist of nested HTML elements.

This example contains 4 HTML elements:

<!DOCTYPE html>
<html>
<body>

<h1>My First Heading</h1>

<p>My first paragraph.</p>

</body>
</html>

Demo

HTML Example Explained


The <html> element defines the whole document.

It has a start tag <html> and an end tag </html>.

The element content is another HTML element (the <body> element).

<html>

<body>
  <h1>My First Heading</h1>
  <p>My first paragraph.</p>
</body>

</html>
The <body> element defines the document body.

It has a start tag <body> and an end tag </body>.

The element content is two other HTML elements (<h1> and <p>).

<body>
  <h1>My First Heading</h1>
  <p>My first paragraph.</p>
</body>
The <h1> element defines a heading.

It has a start tag <h1> and an end tag </h1>.

The element content is: My First Heading.

<h1>My First Heading</h1>
The <p> element defines a paragraph.

It has a start tag <p> and an end tag </p>.

The element content is: My first paragraph.

<p>My first paragraph.</p>

Don't Forget the End Tag

Some HTML elements will display correctly, even if you forget the end tag:

<!DOCTYPE html>
<html>
<body>

<p>This is a paragraph.
<p>This is a paragraph.

</body>
</html>

Demo
The example above works in all browsers, because the closing tag is considered optional.

Never rely on this. It might produce unexpected results and/or errors if you forget the end tag.

Empty HTML Elements


HTML elements with no content are called empty elements.

<br> is an empty element without a closing tag (the <br> tag defines a line break).

Empty element can be "closed" in the opening tag like this: <br />.

HTML5 does not require empty elements to be closed. But if you need stricter validation, and make your document readable by XML parsers, please close all HTML elements.

HTML Tip: Use Lowercase Tags


HTML tags are not case sensitive: <P> means the same as <p>.

The HTML5 standard does not require lowercase tags, but W3C recommends lowercase in HTML4, and demands lowercase for stricter document types like XHTML.
Read More

10/11/2014

JavaScript - Document Object Model or DOM

| |
0 comments
A Document object represents the HTML document that is displayed in that window. The Document object has various properties that refer to other objects which allow access to and modification of document content.

The way that document content is accessed and modified is called the Document Object Model, or DOM. The Objects are organized in a hierarchy. This hierarchical structure applies to the organization of objects in a Web document.
  • Window object: Top of the hierarchy. It is the outmost element of the object hierarchy.
  • Document object: Each HTML document that gets loaded into a window becomes a document object. The document contains the content of the page.
  • Form object: Everything enclosed in the <form>...</form> tags sets the form object.
  • Form control elements: The form object contains all the elements defined for that object such as text fields, buttons, radio buttons, and checkboxes.

Here is a simple hierarchy of few important objects:
There are several DOMs in existence. The following sections explain each of these DOMs in detail and describe how you can use them to access and modify document content.

    The Legacy DOM: This is the model which was introduced in early versions of JavaScript language. It is well supported by all browsers, but allows access only to certain key portions of documents, such as forms, form elements, and images.

    The W3C DOM: This document object model allows access and modification of all document content and is standardized by the World Wide Web Consortium (W3C). This model is supported by almost all the modern browsers.

    The IE4 DOM: This document object model was introduced in Version 4 of Microsoft's Internet Explorer browser. IE 5 and later versions include support for most basic W3C DOM features.

DOM compatibility:


If you want to write a script that uses the W3C DOM when it is available, and otherwise uses the IE 4 DOM if it is available, you can use a capability-testing approach that first checks for the existence of a method or property to determine whether the browser has the capability you desire. 

For example:

if (document.getElementById) {

  // If the W3C method exists, use it

}

else if (document.all) {

  // If the all[] array exists, use it

}

else {

  // Otherwise use the legacy DOM

}
Read More

Check Your Codes

Check the result of your (sample) HTML,CSS,JavaScript code.