Tuesday, July 21, 2015

PHP AND MY SQL TUTORIAL FREE

PHP AND MY SQL TUTORIAL FREE.

introduction 

php stand for hyper text  pre-processor which is an open source web development language used for dynamic website.and application also.
or in other words we say PHP is a server side scripting language software or tools which is used for creating powerful dynamic website ,web application and desktop application.
php is used free for web programing language which is used for creating interactive website.
php is a server side web development language which must require a server for execution.

what can we create with php.

  • we can create web applications using php.
  • we can create dynamic website using php.
  • we can create social network sites using php such as facebook ,twittwer and my space etc.
  • we can create e-commerce online shopping stores such as olx.com
  • we can create news sites such as bbc.com 
  • we can create small applications such as online clocks ,calculators ,image sliders ,love converters ,visitor counter etc
  • we can create desktop applications such as data storing software ,image editing software etc

how does php works.

php codes can be written inside html document,but php require a web server in order to be executed .
php is actually software which is installed on a web server from where it performs the tasks given by developers and return the out put on visitors 'browser within millisecond.
php syntax is little bit simple and similar to java and asp of Microsoft.
php can be written inside html document anywhere in the <body> section or in the <head> section or outside the html tag.
a simple php script is written like as 
<?php
code is here
?

TOOLS REQUIRED TO RUN PHP;

  • a web server (for performing all tasks)
  • a database (storing data)
  • a latest version of php software
  • a text editor 
  • a web browser(for viewing the output)
the best software for this process is ''wamp'' which is include all option like php,apache server ,mysql database etc

Execute PHP Online

For most of the examples given in this tutorial you will find Try it option, so just make use of this option to execute your PHP programs at the spot and enjoy your learning
try the following codes as given below

PHP - Coding Standard

Every company follows a different coding standard based on their best practices. Coding standard is required because there may be many developers working on different modules so if they will start inventing their own standards then source will become very un-manageable and it will become difficult to maintain that source code in future.
Here are several reasons why to use coding specifications:
  • Your peer programmers have to understand the code you produce. A coding standard acts as the blueprint for all the team to decipher the code.
  • Simplicity and clarity achieved by consistent coding saves you from common mistakes.
  • If you revise your code after some time then it becomes easy to understand that code.
  • Its industry standard to follow a particular standard to being more quality in software.
There are few guidelines which can be followed while coding in PHP.
  • Indenting and Line Length - Use an indent of 4 spaces and don't use any tab because different computers use different setting for tab. It is recommended to keep lines at approximately 75-85 characters long for better code readability.
  • Control Structures - These include if, for, while, switch, etc. Control statements should have one space between the control keyword and opening parenthesis, to distinguish them from function calls. You are strongly encouraged to always use curly braces even in situations where they are technically optional.
  • Examples:
    if ((condition1) || (condition2)) {
        action1;
    } elseif ((condition3) && (condition4)) {
        action2;
    } else {
        default action;
    }
    You can write switch statements as follows:
    switch (condition) {
    case 1:
        action1;
        break;
    
    case 2:
        action2;
        break;
    
    default:
        defaultaction;
        break;
    }
  • Function Calls - Functions should be called with no spaces between the function name, the opening parenthesis, and the first parameter; spaces between commas and each parameter, and no space between the last parameter, the closing parenthesis, and the semicolon. Here's an example:
    $var = foo($bar, $baz, $quux);
    
  • Function Definitions - Function declarations follow the "BSD/Allman style":
    function fooFunction($arg1, $arg2 = '')
    {
        if (condition) {
            statement;
        }
        return $val;
    }
  • Comments - C style comments (/* */) and standard C++ comments (//) are both fine. Use of Perl/shell style comments (#) is discouraged.
  • PHP Code Tags - Always use <?php ?> to delimit PHP code, not the <? ?> shorthand. This is required for PHP compliance and is also the most portable way to include PHP code on differing operating systems and setups.
  • Variable Names -
    • Use all lower case letters
    • Use '_' as the word separator.
    • Global variables should be prepended with a 'g'.
    • Global constants should be all caps with '_' separators.
    • Static variables may be prepended with 's'.
  • Make Functions Reentrant - Functions should not keep static variables that prevent a function from being reentrant.
  • Alignment of Declaration Blocks - Block of declarations should be aligned.
  • One Statement Per Line - There should be only one statement per line unless the statements are very closely related.
  • Short Methods or Functions - Methods should limit themselves to a single page of code.
There could be many more points which should be considered while writing your PHP program. Over all intension should be to be consistent throughout of the code programming and it will be possible only when you will follow any coding standard. YOu can device your own standard if you like something different.

PHP & MySQL

MySQL is the most popular Open Source Relational SQL database management system. MySQL is one of the best RDBMS being used for developing web-based software applications.
This tutorial will give you quick start with MySQL and make you comfortable with MySQL programming.

Audience

This reference has been prepared for the beginners to help them understand the basics to advanced concepts related to MySQL languages.

Prerequisites

Before you start doing practice with various types of examples given in this reference, I'm making an assumption that you are already aware about what is database, especially RDBMS and what is a computer programming language.

MySQL Database Export - Backup Methods

The simplest way of exporting a table data into a text file is using SELECT...INTO OUTFILE statement that exports a query result directly into a file on the server host.

Exporting Data with the SELECT ... INTO OUTFILE Statement:

The syntax for this statement combines a regular SELECT with INTO OUTFILE filename at the end. The default output format is the same as for LOAD DATA, so the following statement exports the tutorials_tbl table into /tmp/tutorials.txt as a tab-delimited, linefeed-terminated file:
mysql> SELECT * FROM tutorials_tbl 
    -> INTO OUTFILE '/tmp/tutorials.txt';
You can change the output format using options to indicate how to quote and delimit columns and records. To export the tutorial_tbl table in CSV format with CRLF-terminated lines, use this statement:
mysql> SELECT * FROM passwd INTO OUTFILE '/tmp/tutorials.txt'
    -> FIELDS TERMINATED BY ',' ENCLOSED BY '"'
    -> LINES TERMINATED BY '\r\n';
The SELECT ... INTO OUTFILE has the following properties:
  • The output file is created directly by the MySQL server, so the filename should indicate where you want the file to be written on the server host. There is no LOCAL version of the statement analogous to the LOCAL version of LOAD DATA.
  • You must have the MySQL FILE privilege to execute the SELECT ... INTO statement.
  • The output file must not already exist. This prevents MySQL from clobbering files that may be important.
  • You should have a login account on the server host or some way to retrieve the file from that host. Otherwise, SELECT ... INTO OUTFILE likely will be of no value to you.
  • Under UNIX, the file is created world readable and is owned by the MySQL server. This means that although you'll be able to read the file, you may not be able to delete it.

Exporting Tables as Raw Data:

The mysqldump program is used to copy or back up tables and databases. It can write table output either as a raw datafile or as a set of INSERT statements that recreate the records in the table.
To dump a table as a datafile, you must specify a --tab option that indicates the directory, where you want the MySQL server to write the file.
For example, to dump the tutorials_tbl table from the TUTORIALS database to a file in the /tmp directory, use a command like this:
$ mysqldump -u root -p --no-create-info \
            --tab=/tmp TUTORIALS tutorials_tbl
password ******

Exporting Table Contents or Definitions in SQL Format:

To export a table in SQL format to a file, use a command like this:
$ mysqldump -u root -p TUTORIALS tutorials_tbl > dump.txt
password ******
This will a create file having content as follows:

-- MySQL dump 8.23
--
-- Host: localhost    Database: TUTORIALS
---------------------------------------------------------
-- Server version       3.23.58

--
-- Table structure for table `tutorials_tbl`
--

CREATE TABLE tutorials_tbl (
  tutorial_id int(11) NOT NULL auto_increment,
  tutorial_title varchar(100) NOT NULL default '',
  tutorial_author varchar(40) NOT NULL default '',
  submission_date date default NULL,
  PRIMARY KEY  (tutorial_id),
  UNIQUE KEY AUTHOR_INDEX (tutorial_author)
) TYPE=MyISAM;

--
-- Dumping data for table `tutorials_tbl`
--

INSERT INTO tutorials_tbl 
       VALUES (1,'Learn PHP','John Poul','2007-05-24');
INSERT INTO tutorials_tbl 
       VALUES (2,'Learn MySQL','Abdul S','2007-05-24');
INSERT INTO tutorials_tbl 
       VALUES (3,'JAVA Tutorial','Sanjay','2007-05-06');
To dump multiple tables, name them all following the database name argument. To dump an entire database, don't name any tables after the database as follows:
$ mysqldump -u root -p TUTORIALS > database_dump.txt
password ******
To back up all the databases available on your host, use the following:
$ mysqldump -u root -p --all-databases > database_dump.txt
password ******
The --all-databases option is available as of MySQL 3.23.12.
This method can be used to implement a database backup strategy.

Copying Tables or Databases to Another Host:

If you want to copy tables or databases from one MySQL server to another, then use mysqldump with database name and table name.
Run the following command at source host. This will dump complete database into dump.txt file:
$ mysqldump -u root -p database_name table_name > dump.txt
password *****
You can copy complete database without using a particular table name as explained above.
Now, ftp dump.txt file on another host and use the following command. Before running this command, make sure you have created database_name on destination server.
$ mysql -u root -p database_name < dump.txt
password *****
Another way to accomplish this without using an intermediary file is to send the output of mysqldump directly over the network to the remote MySQL server. If you can connect to both servers from the host where source database resides, use this command (Make sure you have access on both the servers):
$ mysqldump -u root -p database_name \
       | mysql -h other-host.com database_name
The mysqldump half of the command connects to the local server and writes the dump output to the pipe. The remaining mysql half of the command connects to the remote MySQL server on other-host.com. It reads the pipe for input and sends each statement to the other-host.com server.

No comments:

Post a Comment