Manual of PHP

 
 
 

Web map

 
rim   rim
Carriedarrow The language SQL and PHP

 

The language SQL and PHP To print E-mail

In this chapter we will devote ourselves to explain the language SQL since later we will use it very much in the PHP connections with MySQL.

Creation and modification of Stage in SQL

MySQL is organized from stage and the above mentioned stage contains fields. Every field is capable of containing a type of fact. The types of information that it is possible to create in the language SQL are:

Type Description
Tinyint [Unsigned] I inform from 0 to 255 or from-128 to 128
Smallint [Unsigned] I inform from 0 to 65535 or from-32768 to 32768
Int or Integer Normal point. Status from-2147483648 to 214783648
Float [(M, D)] Number of floating comma of simple precision if no argument passes M is the digits and D the of decimal
Double [(M, D)] Number of floating comma of double precision. He always has sign M and D
Decimal [(M [D])] Number stored like chain of characters M is the entire number of digits and D the of decimal
Date Type dates. It admits formats "AAAA-MM-DD" or "AA-MM-DD" or "AAMMDD"
Steal Type hour. There allows format "HH:MM:SS" or "HHMMSS" or "HHMM" or "HH"
Char (length) Chain of characters of the stated length. The space is reserved in characters although they are not used
Varchar (length) Chain of characters of the stated length that is stored by his occupation. Maximum length: 255 characters
Blob Type destined to store bits without intrepretar. It is used to store longer text of 255 characters. It differentiates small letters capital letters.
Text Type destined to store bits without intrepretar. It is used to store longer text of 255 characters. It does not differentiate small letters capital letters.

To create a table we will use the following syntax:

ONE BELIEVE TABLE Nombre_tabla
(Campo1  Tipo_dato  Not Null,
 Campo2 Tipo_dato,
 PRIMARY KEY (Campo3));

This would create a table to us with 3 fields of which Campo3 is the only value, that is to say, that cannot be sobreescrito.

To eliminate a table we will use:

DROP TABLE Nombre_tabla;

To modify the structure of the table we will use the following syntax:

ALTER TABLE Nombre_tabla
[ADD Nombre_atributo Definition]    //He would Add a new field
[CHANGE AntiguoNombreAtributo NuevoNombreAtributo Definition]    //It would Change a field
[DROP NombreAtributo];    //It would Erase a field

The indexes are a structure of access that the information contained in a table allows to organize. To create an index we would use the following syntax:

ONE BELIEVE [UNIQUE] INDEX NombreIndice
  ON Table (Fields);

Information manipulation

- information insertion

To insert information in the table it is realized by means of the command insert and his syntax is the following one:

INSERT INTO NombreTabla [Campo1, Campo2... CampoN] VALUE (Valor1, Valor2... ValorN);

- Information consultations

For this action we use the command SELECT and the syntax is the following one:

SELECT ([*] / [Attributes]) FROM Tabla/s [WHERE ListaCondiciones] [GROUP BY Stood out] [HAVING ListaCondiciones] [ORDER BY Stood out]

A set of functions exists inside the consultations of information that allow us to obtain information or realize operations with regard to the lines. The functions are:

function Description
COUNT (*/DISTINCT I Stand out) It counts the number of lines
SUM (Field) It adds the values of the stated attribute
AVG (Field) It obtains the arithmetical average of the attribute
MAX (Field) It obtains the maximum value of the attribute
MIN (Field) It obtains the minimal value of the attribute

- Elimination of information

To eliminate information we use the judgment DELETE whose syntax is the following one:

DELETE FROM NombreTabla [WHERE Condition];

Previous chapter:
Operations with Files

Following chapter:
Connection with MySQL



 

 
Front
Chapters of the Manual of PHP
Introduction to PHP
Variables
My First Script PHP
Operators in PHP
Structures of Control
Functions in PHP
Code inclusion
Counterfoils (array)
Chains of Characters
Classes
Dates
Entry and Exit
Operations with Files
The language SQL and PHP
Connection with MySQL
Meetings
Forms with PHP
To practise in line
List of practices in line
FAQ
Frequent questions
Codes PHP
List of Codes PHP
Forums
Forums PHP
Other Manuals
Manuals of other languages
 
   
 
 
MySpaceScripts.info - Sitemap - Contact us - Sitemap - Contact us - Sitemap - Contact us

caza polonia , packaging , Mehrgenerationenhaus , Cool QSL Print Service , waagen , Li-Ion Battery for IBM , Patek Philippe Replika Uhren