Category: MySQL

Byte Insight

MySql – Insert

Inserting rows into MySql can be done in a couple of ways. You can use the INSERT…VALUES and INSERT…SET commands.

MySql

MySql is the worlds second most popular database engine (July 2013) and its open source. It is based on SQL (Sequential Query Language).  Unlike MS Access it does not run as a stand-alone application.   It runs as a background service on a computer (typically called ‘a server’) and you connect to it using a username and password.  Once you have connected to the MySql server you can query it using SQL or Structured Query Language.  The server will respond with the results of your query.

MySql – Create Database

If you need to create a database via the command line (or through the MYSQL prompt in PHPMyAdmin) then you can use the following where dynamo is the name of the database you wish to create. See W3Schools/Create DB for more information.

CREATE DATABASE dynamo;

MySQL – Create Table

The process and command for creating a table in MySql are similar to that for a database. You will need to make decisions about data types and key fields. Detailed information on creating tables is available at W3Schools/Create Table.

MySql – Feedback

Getting helpful feedback from MySQL when it errors is possible if you use the following:

mysql_query($sql) or die('Some useful message:' . mysql_error() );

MySql – Relationships

Dealing with relationships in MySql is not as straightforward as either MS Access or as you would have hoped for. Creating simple primary keys isn’t too difficult

MySql – Connections

Connecting to the MySql database via PHP is done through the CONNECT functions.

MySql – Select

SELECTING DATA

To grab a bunch of data from an SQL database you need to write a SELECT query.

MySql – Delete

If you need to delete a row you can use the DELETE command with a WHERE clause dictating which ones:

DELETE FROM tbl_nameWHERE fieldx = "X";

Example

DELETE FROM criminals WHERE crime = "Arson";

Further Information and examples here