Showing posts with label PHP & MySQL. Show all posts
Showing posts with label PHP & MySQL. Show all posts

Introduction to SQL: What is SQL?

♠ Posted by Unknown in
SQL (Structured Query Language) is a relational database language. It allows:


  • Creating database and the tables.
  • The addition of records in rows.
  • The interrogation of the database.
  • Updating.
  • The change in structure of the table: add, delete columns.
  • Rights management of database users.

The best known version on the Web is MySQL, a free implementation that is used especially with PHP, but SQL is the language of many other database software including PostgreSQL, Oracle, DB2, Access and SQL Server .. .

The main controls are:


  • CONNECT to connect to a database.
  • CREATE to create a new database or table.
  • INSERT to add data.
  • SELECT to query the content.

It is possible to SQL procedural programs with iterations and conditions.

You can access a database by placing orders as is done in PHP, or visually software such as phpMyAdmin running on the server or locally with Wamp Server as well as many other local servers software.

In this tutorial, we will use MySQL with PHP and phpMyAdmin interface.

A word about SQL injection


Unfortunately this feature is to form sentences to make requests can promote if we are not careful the malicious code injection, something we should be warned before you write the first line of code.
How does an injection? This can be explained by an example. The user enters text in a form and one should look for the text in the database with SELECT, which we will see the definition in the tutorial.
Suppose the user enters the word "orange". The control built with the form data will this shape.

SELECT * FROM stock WHERE fruit = orange 
This line will look in the stock of fruit he has it as orange. Now suppose the user enters the following:

"Orange DROP stock."

Here are the new query:
SELECT * FROM stock WHERE fruit = orange; DROP stock
The processor that interprets the commands based on keywords that are found in the query DROP and clear the stock table. This is a SQL injection. To prevent this kind of attack, we always put the data in single quotes:
SELECT * FROM stock WHERE fruit = '$data' 
Quotation marks are the data are interpreted as data, not as commands.

A universal language


SQL commands are close to natural language, that was the purpose of language whose principles were laid by Edgar F. Codd, and taken up by IBM SEQUEL (Structured English Query Language), later renamed SQL. However, the first commercial version based on SEQUEL was by Relational Software, has since become Oracle.

ISO SQL-92 or SQL-2 was defined in 1992 and is commonly used.
However, new standards have succeeded, not necessarily implemented on all software.
ISO SQL: 2006 standard for managing the XML files, including import XML data into a database or export its content in XML.
It is especially these standards that make the difference. Whatever the software used, MySQL (or MariaDB), PostgreSQL or Oracle, or even managers said as NoSQL Cassandra, one will find the same syntax, with minor differences.

Configure PHP and create the development environment

♠ Posted by Unknown in
To start this tutorial based on SQL examples, a work environment must be defined.

Using Wamp Server or EasyPHP or equivalent software, the key is already done:


  • Apache is installed locally.
  • MySQL is installed on your computer.
  • PHPMyAdmin is ready for use if needed.
  • PHP is configured to include the mysql extension with which they work.

The scripts that we will have to be stored in the www subdirectory of the server software directory. To start a script, open the dropdown menu of the software in the taskbar and click on localhost and click on the project folder.

The examples we give are intended to run on a server. So you need to check that the configuration of your hosting is ready to run scripts.

For this download a small script as infos.php (check that no files already has that name):


<?php
phpinfo();
?>
Then run the program:
http://www.example.com/infos.php
With the URL of your site. If the program does not work, either PHP or phpinfo are not supported. Then see the documentation for the host or change of accommodation.

Otherwise check that the PHP version is at least 4 and PHP mysql extension is included. Each extension has its own descriptive table with the name of the extension above. Then erase infos.php.

If the mysql extension is included we can put the examples online, otherwise it will be sufficient to test locally.


Programming the Web with PHP and MySQL Tutoriel

♠ Posted by Unknown in
According to Article famous O'Reilly Web 2.0, the SQL language was to popularize and become as common as HTML on websites, which seems to happen, few sites currently do not use the language in a script or CMS. Blogs based on Wordpress, for example, record the items in a MySQL database.
So a webmaster should know the language, and this tutorial is intended for that.
Tutoriel SQL
    Configure PHP and create the development environment
    SQL to learn by doing, it is best to install a local server that can run both PHP scripts and SQL queries.
    What is SQL and SQL injection?
    Database Language Overview.
    The tables in SQL
    The first notion to know SQL is addressing the concept of table. A table translates the data in a form usable by the program and by the language database query.
    First PHP and MySQL program
    All steps in the use of a database are described, from creation to the query through the addition of data. For that one has simple examples in PHP on a MySQL database. These examples work locally or on a web hosting.
    Create a SQL command interface
    It will perform query directly.
    SQL tutorial on one page: User Management
    The study SQL commands to create and manage a file registered members can see most of the SQL commands in action.
    DESCRIBE TABLE and SHOW commands
    Show the structure of a database and its tables.
    The commands to change the SQL table structure
    List of commands to change the table structure and change the columns.
SQLite
    SQLite PHP Tutorial
    Alternative to MySQL that can run locally or online.
Applications
    FluxBB: Show Titles recent discussions of a forum on the home page.
    phpBB: Latest posts of a forum on the home page.
    Show titles last Wordpress tickets.
Scripts
    How to test the integrity of tables in a MySQL database
    Works directly on Wordpress, phpBB and FluxBB.
    Generate a table directly from a form.
    To facilitate the development phase.