The four statement for connecting to the mysql database using php are

  1. mysql_connect()  to connect to the server
  2. mysql_select_db()   selects the specific data base to connect to
  3. mysql_query()    sends and sql statement to the server
  4. mysql_fetch_array()  returns the data from the server

One can also use mysqli commands which allows one to one more then one database at a time. The mysqli are the improved mysql functions.  They have more capability then the start mysql functions such as with mysqli you can open more then one database at a time where with mysql you can open only one database at a time.

Comments (0)

Three elements to an SQL command.

  • keyword
  • identifier
  • optionally one or more literals

BASIC SQL KEYWORDS

  • Select - retrieve data records from a table
  • Insert - add new data record to a table
  • Delete - remove a data record from a table
  • update - Modify data within an existing record in a table.

Identifiers

define the database object in the keyword command.  Can be either a database name, table name, or the names of data fields. Tells use with table to select the data element requested.

literals

Define specific data values referenced by the keyword. String literals must be enclosed in quotes.

Database querys

SQL SELECT statement the searches the database for specific data records.

SELECT datafields FROM table

use commas to separate each data field. When the records that match the query are returned you can determine which data fields to return.  An asterisk will return all fields. Default returns all the data records in the specified table.

SQL SELECT MODIFIERS

WHERE - display a subset of records that meet a specified condition

ORDER BY - display records in a specified order

LIMIT - display only a subset of records

An example of a where statement which allows you to specify conditions to filter data from the results set.

SELECT recipeid, title FROM recipes WHERE recipeid = 1

The order by statement specifies the data field (or fields) you want the returned data to be sorted. This can be ASC or DESC, ascending or descending sort.
an example would be
SELECT commentid, comment FROM comments ORDER BY commentid DESC

The limit statement specifies the starting record and the following number of records to be returned. The starting record is an offset within the returning records and not the actual record id.The offest value starts at 0 and goes to number of records returned in the statement.
An example would be
SELECT recipeid, title FROM recipes ORDER BY recipeid DESC LIMIT 0, 5

 

 

Comments (0)

Terms


database - a grouping of related information into a single container.  Needs a unique name on the server. Can be up to 64 characters. Cannot start with a space. No forward or backward slashes, exclamation points or asterisks. Spaces are allowed within the name but not recommended.

table - a subset of data within a database, which contains a grouping of similar data items.

data fields - hold individual data elements within a table. This is where the application actually stores the data.

data records - the table groups data fields into data records. Each data record is the information about one occurrence of given set of data fields.

 data type - each data field must be identified as to the type of data that will be stored there.

data constraints - controls how you place data in a data field.

data constraint - primary key -Most popular data constraint is a primary key. MySQL creates a hidden table to relate the primary key values to the records numbers and then retrieves the query data based on the primary key information.

data constrain - IS NULL - If this is present then a value has to be entered into a data field. Primary key cannot have an empty field (this is automatic for all records).

 

 

Comments (0)

If (conditional)

 {   php statements if condition true

 php statement 1

    php statement 2

   php statement 3

 }

else

 { php statement if condition was false

php statement 1

   php statement 2

   etc

 }

 

If you want more then one else statement the first else state becomes an elseif

 

 

Comments (0)

== equal to

!= not equal to

< less then

> greater then

<= less then or equal to

>= greater then or equal to

 

Comments (0)