PHP and MySql - The Art of Linda Thu, 19 Sep 2019 06:42:36 -0700 Joomla! - Open Source Content Management en-gb mysql statement to retrieve data 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.

Php and MySql Wed, 11 Sep 2013 16:41:58 -0700
MySQL Intro Three elements to an SQL command.

  • keyword
  • identifier
  • optionally one or more literals


  • 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.


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.


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.


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



Php and MySql Sat, 07 Sep 2013 20:57:31 -0700
MySQL database info 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).



Php and MySql Fri, 30 Aug 2013 18:27:20 -0700
If Then Statements php If (conditional)

 {   php statements if condition true

 php statement 1

    php statement 2

   php statement 3



 { php statement if condition was false

php statement 1

   php statement 2




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



Php and MySql Wed, 28 Aug 2013 19:31:09 -0700
Comparison Operators in php == equal to

!= not equal to

< less then

> greater then

<= less then or equal to

>= greater then or equal to


Php and MySql Wed, 28 Aug 2013 19:27:53 -0700
php overview A php variable is identied by a leading dollar sign $ in front of the variable.  The variable name can start with either a letter or an underscore _  The name can only contain letters, numbers or underscores.  No spaces.

Assignment statements are used to give variables values i.e.    $name="Linda";

all statements end with a semi-colon ;

String values must be enclosed in quotes.

Variable types do not need to be declared.  The can go from string to numeric to string.

Variables can be inserted into an echo statement i.e.,

echo "my name is $name\n";

To start a new line one need to put a line break in the code before \n  The statement would read:

echo "my name is $name <br/> \n;

Array Variables

Array variables are assigned in an assignment statement with (...) around the values and the word array in front of the (. There is also a comma between each element.  i.e.

$name=array("linda" ,"Peter", "Sean")

Array variables are reference by numbers between brackets [ ] The numbering system starts with 0 This is called a numerical array because it uses numbers to reference the array.

Associative Array uses a string key value to identify the data values.  An example of an associative array of names would be:

$associativename = array("Girl"=> "Linda", "Boy"=>"John");

echo "The Girl is {$associativename["Girl"]} <br />\n";

echo "The Boy is {$associativename ["Boy"]}  <br />\n";

Be sure to put the ending bracket after the ].  So it would be {$...[ ]}

Also do not forget the closing quotes.

Arithmetic codes

+ addition

- subtraction

* multiplication

/ division

%  modulus




Php and MySql Fri, 23 Aug 2013 21:01:36 -0700