Welcome to S-Design
The home of your bespoke, professional, fast-loading, interactive, database-driven web presence.
Menu
Merry Christmas Everyone
MySQL TUTORIALS


MySQL Basics

A database is a collection of information that is organized so that it can easily be accessed, managed, and updated. In one view, databases can be classified according to types of content: bibliographic, full-text, numeric, and images.
In computing, databases are sometimes classified according to their organizational approach. The most prevalent approach is the relational database, a tabular database in which data is defined so that it can be reorganized and accessed in a number of different ways.
Computer databases typically contain aggregations of data records or files, such as sales transactions, product catalogs and inventories, and customer profiles.

MySQL is not a database, but a Database Management System (DBMS). Any collection of data stored using this system is known as a database.
There are many types of DBMS... Oracle, IBM DB2, Microsoft SQL Server, Microsoft Access, PostgreSQL, MySQL, and SQLite.
A database is not generally portable across different DBMS, but different DBMSs can inter-operate to some degree by using standards like SQL. This means that choosing the right DBMS is important, if you should ever wish to move your databases. Although many share the same syntax (SQL)... there are many differences, so code that may work with MySQL, might not work with Microsoft SQL.

What is SQL?
Database programs have many different methods for storing and retrieving data, as well as for organising the stored data on the computer. One popular way for accessing data, both to store and to retrieve it, is to use a computer language called "SQL" (Simple Query Language). SQL was specially designed for database access.

Why should I use MySQL?
The MySQL database has become the world's most popular open source database because of its high performance, high reliability and ease of use. It is also the database of choice for a new generation of applications built on the LAMP stack (Linux, Apache, MySQL, PHP / Perl / Python.) Many of the world's largest and fastest-growing organizations including Facebook, Google, Adobe, Alcatel Lucent and Zappos rely on MySQL to save time and money powering their high-volume Web sites, business-critical systems and packaged software.
MySQL runs on more than 20 platforms including Linux, Windows, Mac OS, Solaris, IBM AIX, giving you the kind of flexibility that puts you in control. As such, you typically find MySQL preinstalled on virtually all Web Hosting.

How do I create a database?
In most web hosting environment, you cannot create a database via code... i.e. via PHP. You will need to create your database through the web hosts admin panel, and then you can use PHP or PHP MyAdmin to builds the tables in that database.

If you are allowed to create a database via PHP, here's how you do it: <?PHP

$DBhost = "mysql.mywebsite.com";
$DBuser = "my_username";
$DBpass = "my_password";

$DBname='my_database';

$connect = @mysql_connect($DBhost,$DBuser,$DBpass); if(!$connect){ die('Could not connect: ' . mysql_error()); }

if(@mysql_query("CREATE DATABASE $DBname",$connect)) {
echo "Database created";
}
else {
echo "Error creating database: " . mysql_error();
}

mysql_close($connect);

?>
We're setting the location of the database (your web hosting provider will tell you this) to a PHP variable called $DBhost.
We're setting your username for the database to a PHP variable called $DBuser.
We're setting your password for the database to a PHP variable called $DBpass.
We're setting the name of the database you wish to create to a PHP variable called $DBname.
We then perform the connection to the database host (using the $DBhost, $DBuser & $DBpass we set just set) and store a reference to it in a PHP variable called $connect. Notice the "@" symbol prefixed to the "mysql_connect()" function... that tells PHP not to print out any error messages if there is a problem establishing a connection to the database.
If the connection was established OK (if($connect)), we then tell MySQL to create a database called my_database (using the $DBname we just set).

You should only need to run this kind of script once per database, and should then delete this script from your hosting, so it can't be accidentally run again.

Title