Web Tutorial

Sunday, August 19, 2012

Advanced Photo Gallery with HTML

Many web servers provide Photo Gallery, Photo Gallery, known for the web in php, asp, Flash and Java, or contained in the CMS that can be installed through Fantastico.

Screen 1:





Screen 2 :





Friday, August 17, 2012

Using MySQL with Apache

There are programs that let you authenticate your users from a MySQL database and also let you write your log files into a MySQL table.
You can change the Apache logging format to be easily readable by MySQL by putting the following into the Apache configuration file:

LogFormat \
"\"%h\",%{%Y%m%d%H%M%S}t,%>s,\"%b\",\"%{Content-Type}o\", \
\"%U\",\"%{Referer}i\",\"%{User-Agent}i\""

To load a log file in that format into MySQL, you can use a statement something like this:

LOAD DATA INFILE '/local/access_log' INTO TABLE tbl_name
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' ESCAPED BY '\\'

The named table should be created to have columns that correspond to those that the LogFormat line writes to the log file.

Using mysql in Batch Mode

To do this, put the commands you want to run in a file, then tell mysql to read its input from the file:

shell> mysql < batch-file

If you are running mysql under Windows and have some special characters in the file that cause problems, you can do this:

C:\> mysql -e "source batch-file"

If you need to specify connection parameters on the command line, the command might look like this:

shell> mysql -h host -u user -p < batch-file
Enter password: ********

When you use mysql this way, you are creating a script file, then executing the script.
If you want the script to continue even if some of the statements in it produce errors, you should use the --force command-line option.
Why use a script? Here are a few reasons:
  • If you run a query repeatedly (say, every day or every week), making it a script enables you to avoid retyping it each time you execute it.
  • You can generate new queries from existing ones that are similar by copying and editing script files.
  • Batch mode can also be useful while you're developing a query, particularly for multiple-line commands or multiple-statement sequences of commands. If you make a mistake, you don't have to retype everything. Just edit your script to correct the error, then tell mysql to execute it again.
  • If you have a query that produces a lot of output, you can run the output through a pager rather than watching it scroll off the top of your screen: shell> mysql < batch-file | more
  • You can catch the output in a file for further processing: shell> mysql < batch-file > mysql.out
  • You can distribute your script to other people so that they can also run the commands.
  • Some situations do not allow for interactive use, for example, when you run a query from a cron job. In this case, you must use batch mode.
The default output format is different (more concise) when you run mysql in batch mode than when you use it interactively. For example, the output of SELECT DISTINCT species FROM pet looks like this when mysql is run interactively:

+-------------+
| species    |
+-------------+
| bird           |
| cat             |
| dog           |
| hamster   |
| snake       |
+-------------+

In batch mode, the output looks like this instead:

species
bird
cat
dog
hamster
snake

If you want to get the interactive output format in batch mode, use mysql -t. To echo to the output the commands that are executed, use mysql -vvv.
You can also use scripts from the mysql prompt by using the source command or \. command:

mysql> source filename;
mysql> \. filename

See Executing SQL Statements from a Text File, for more information.

Getting Information About Databases and Tables

What if you forget the name of a database or table, or what the structure of a given table is (for example, what its columns are called)? MySQL addresses this problem through several statements that provide information about the databases and tables it supports.
You have previously seen SHOW DATABASES, which lists the databases managed by the server. To find out which database is currently selected, use the DATABASE() function:

mysql> SELECT DATABASE();
+----------------+
| DATABASE() |
+----------------+
| menagerie   |
+---------------+

If you have not yet selected any database, the result is NULL.
To find out what tables the default database contains (for example, when you are not sure about the name of a table), use this command:
mysql> SHOW TABLES;






The name of the column in the output produced by this statement is always Tables_in_db_name, where db_name is the name of
the database. See SHOW TABLES Syntax, for more information.
If you want to find out about the structure of a table, the DESCRIBE statement is useful; it displays information about each of a table's
columns:
mysql> DESCRIBE pet;

Field indicates the column name, Type is the data type for the column, NULL indicates whether the column can contain NULL values, Key indicates whether the column is indexed, and Default specifies the column's default value. Extra displays special information about columns: If a column was created with the AUTO_INCREMENT option, the value will be auto_increment rather than empty.

DESC is a short form of DESCRIBE. See DESCRIBE Syntax, for more information.
You can obtain the CREATE TABLE statement necessary to create an existing table using the SHOW CREATE TABLE statement. See SHOW CREATE TABLE Syntax.
If you have indexes on a table, SHOW INDEX FROM tbl_name produces information about them. See SHOW INDEX Syntax, for more about this statement.

Wednesday, August 15, 2012

Retrieve Data from MySQL

Select MySQL, is a main command that most often we will use. To be utilize the MySQL database, must learn how to retrieve and save data to MySQL. We will learn how to retrieve data from MySQL first.
To retrieve data from MySQL database server using the command "SELECT MySQL".

The general form of the command "SELECT MySQL" is as below:
SELECT column_name1,column_name2...
FROM tables
[WHERE conditions]
[GROUP BY group
[HAVING group_conditions]
[ORDER BY sort_columns]
[LIMIT limits];
 
 The command "SELECT MySQL" has many options that you can use to set the data selection to suit your needs. The order of these options (FROM, WHERE, GROUP BY, HAVING, ORDER BY and LIMIT) must comply with the above general form.

To select all columns in the table, you can use the notation (*) are considerably shorter than we should list the field names you want to show. For example, when you want to see all the data on all the columns in the students table, you just use the query below.

SELECT * FROM students;

Method Writing of MySQL Query

Syntax or how to write a MySQL query is loose, it means you are free to type enter anywhere without disturbing the code written. Some commands require curly braces ({}), such as insert commands. Just make sure to end each command that you created with a semicolon (;).

To give an idea for you I will write some sample queries and note its simplicity.

MySQL Query Code:
SELECT * FROM name_tabel;
The above code selects all the rows and columns of the table table_name, and display it on us. Here are some more that will query you use very often goes along with our tutorial.

MySQL Query Code:
INSERT INTO name_tabel (Coloum1, coloum2)
VALUES(value1, value2);
UPDATE name_tabel SET coloum1 = value1, coloum2 = value2;