Exercises, examples and other material relating to training module H113. This topic is presented on public courses
This module teaches you some of the PHP functions that let you connect to a MySQL database. It also tells you how to write PHP code that can be used on data held in other relational databases without the need to duplicate or rewrite large amounts of code.
|Articles and tips on this subject||updated|
|4378||What FGW passengers want to talk about / and PHP programming to find out|
Much of my recent talk and examples on this blog recently have stressed robust, tested, re-usable code, and that's vital in the majority of applications. However, there are occasions where a "one-off" is needed such as this morning when I wanted to list the most popular subjects covered on our First ...
|1561||Uploading to a MySQL database through PHP - examples and common questions|
One of the most popular pages on the technical part of our web site relates to the uploading of images to a server from a local disc file via a browser, then storing those images on a database, and displaying them later. Another popular page relates to the same thing with .pdf file - and really the ...
|3455||MySQL, MySQLi, PDO or something else - how best to talk to databases from PHP|
One of the consideration that users of Open Source programming languages have make is which one of many ways to do any particular task. Open Source tends to result in lots of very clever facilities being provided, many of which overlap in their use, and many modules being provided via libraries such ...
|3035||How to display information from a database within a web page|
Are you displaying data that's held in an SQL database from within your own PHP program for the first time? Perhaps you have access to a database that's setup / implemented through a standard open source application such as phpBB, the Simple Machines Forum, or Movable Type or be a colleague?
|2432||Using print_r in PHP to explore mysql database requests|
The print_r function in PHP lets you "print raw" the contents of a variable - great for debugging and far better that print which - if you pass it an array helpfully says Array
Embed your print_r into <pre> to </pre> tags ... so that you get a good display on your browser ... otherwise you'll ...
Delegates sometimes ask me what an "injection attack" is, and for examples. I came across a really good example this morning on (oops!) one of our own pages - it's now fixed, but I'm documenting here and showing you what was happening so that you can learn from it.
Visiting one of the most popular pages ...
|2561||The future of MySQL|
MySQL has grown from a very neat little open source database 10 years ago into a very powerful and widespread database that's not always fully open source any longer today. The MySQL company was bought out by Sun a couple of years back (January 2008), and in turn Oracle are now buying Sun. This deal ...
|2447||MySQL stored procedures / their use on the web from PHP|
Are there times when your PHP will pull a large result set back from MySQL, or have to make a large number of queries, just to further process the data into a relatively small dynamic section of a report? If so, why not have the MySQL do more of the work and return a much shorter, more processes results ...
|2320||Helping new arrivals find out about source code examples|
On 30th July, nearly 5300 people arrived at source code examples on our web site from Google searches, from 4000 unique IP addresses.
How do I know that? From analysing our log files:
-bash-3.2$ grep 'GET \/resources\/ex\.php.*\.google\.' ac_20090730 | grep -v Googlebot | wc
5382 129055 1832168
|2259||Grouping rows for a summary report - MySQL and PHP|
It's quite quick and easy to write a loop that goes through a mysql result set and displays the content on an HTML page (but remember security of data, size of resulting HTML page, and the need to consider special characters such as <). But what if you want a shorter report, grouping records together ...
|2071||Setting up a MySQL database from PHP|
Yes ... training on a Sunday ;-) ... I've been setting up a MySQL database from a PHP script and testing it. A couple of bits of source to share.
1. The setup of the database:
mysql_query("create database gerald");
|1983||Keeping PHP code in database and running it|
The software for these articles lets me enter HTML and keeps it in a database. If I want to add PHP, that gave me a problem as the data (HTML) was simply read from the database and passed to my client's browser without being parsed for <?php to ?> sections. But problem solved in two different ...
|1010||Dates, times, clickable diarys in PHP|
It's that quiet week between Christmas and the New Year that's an excellent chance to catch up - a little - on some of the things that are important but have been abandoned in the mad rush of urgent things these last 9 months. Like writing a booking system and like - I hope - spending long overdue ...
|104||mysql_connect or mysql_pconnect in PHP?|
If you're connecting to a MySQL database in your PHP application, you'll find that there are two alternative connections - mysql_connect which establishes a new connection "each time" and mysql_pconnect which uses persistent connections. Which should you use?
Mysql_connect opens a new connection each ...
|937||Display an image from a MySQL database in a web page via PHP|
There's lots of clever scripts around to tell you how to get images in and out of databases, but nothing simple to show you the principles of including such an image via (say) PHP in a web page. So here goes.
you need TWO URLs - you need the HTML page that's going to contain the image, AND you need ...
|581||Saving a MySQL query results to your local disc for Excel|
Do you want to run a database query on a remote server and save the results into a text file on your LOCAL disc - i.e. the disc of the computer at which you're seated and not the disc of the server that's in a remote location?
It's not as easy as you think it should be. Because of the security risks ...
|947||What is an SQL injection attack?|
An SQL injection attack is where a user of your form enters a piece of SQL code into it, and wraps it in special characters in such a way that the data entered doesn't get used for the purpose you had intended - it gets used to corrupt or destroy your database.
For example, if your form returns to $_REQUEST[message] ...
|915||Paging through hundreds of entries|
I can display all the entries in a table on a single page if there are 10 or 20 of them. When I get up to about 30 or 40 entries, it's getting out of hand ... and with hundreds of entries, I REALLY need a paging system.
Quite commonly, I see requests for "paging systems" to meet such requirements and, ...
|515||MySQL - an FAQ|
We're becoming a serious MySQL resource, with many technical articles, examples, forum posts and blog entries answering those difficult-to-resolve issues you may have come across. You might like to bookmark (or link to) this page.
Eleven recent articles on MySQL ...
Flashbulb moments - facts that ...
|666||Database design - get it right from first principles|
It's VITAL to get your data(base) design more or less right before you write too much code - otherwise you'll end up wasting a lot of time and effort writing kludge code and - worse - forcing your users into work-arounds for the lifetime of the system at great expense to everyone in time, effort and ...
|723||Viewing images held in a MySQL database via PHP|
LOTS of questions on this at the moment. We have a couple of sample scripts that do it - have a look at:
* feeder.php which adds images into a database if they've been uploaded as plain text files, displays them from the database if that's where they are already, and generates a rather more informative ...
Some modules are available for download
as a sample of our material or under an Open Training Notes License
for free download from http://www.training-notes.co.uk
How to create a new table.
Adding information to a table.
Selecting information from a table and reporting it to a web page.
Deleting a table.
User input checking and other testing.
Example: A PHP script to select and view the data in any table.
Downloading all the tables from a database.
Uploading tables from a flat text file.
Using other relational databases from PHP.
Using Oracle 8.x and 9.x.
Using the Oracle OCI9 API.
Portable database connection.
If you are looking for a complete course and not just a information on a single subject, visit our Listing and schedule
Well House Consultants specialise in training courses in
. We run
throughout the UK (and beyond for longer courses), and
at our training centre in Melksham, Wiltshire, England.
It's surprisingly cost effective to come on our public courses -
even if you live in a different
country or continent to us
We have a technical library of over 700 books on the subjects on which we teach.
These books are available for reference at our training centre. Also
available is the Opentalk
Forum for discussion of technical questions.