Posts Tagged ‘where’

MYSQL:Use the explain command

Thursday, July 24th, 2008

Use multiple-row INSERT statements to store many rows with one SQL statement.

The explain command can tell you which indexes are used with the specified query and many other pieces of useful information that can help you choose a better index or query.

Example of usage: explain select * from table

explanation of row output:

* table—The name of the table.
* type—The join type, of which there are several.
* possible_keys—This column indicates which indexes MySQL could use to find the rows in this table. If the result is NULL, no indexes would help with this query. You should then take a look at your table structure and see whether there are any indexes that you could create that would increase the performance of this query.
* key—The key actually used in this query, or NULL if no index was used.
* key_len—The length of the key used, if any.
* ref—Any columns used with the key to retrieve a result.
* rows—The number of rows MySQL must examine to execute the query.
* extra—Additional information regarding how MySQL will execute the query. There are several options, such as Using index (an index was used) and Where (a WHERE clause was used).

PHP:Use “sprintf”

Monday, June 30th, 2008

Example 1.Uncleanly Spliced String.

<?php

$sql = “SELECT col1, col2, col3 FROM people WHERE first_name = ‘” . mysql_real_escape_string($first_name) . “‘ AND last_name = ‘” . mysql_real_escape_string($last_name) . “‘AND foo = ‘” . ($bar = “good” ? “good” : “bad”) . “‘ ORDER BY col1″ ;

?>
I see these types of indecipherable strings –like this SQL statement example– all too frequently. The meaning of this query has been lost due to numerous concatenations and escape functions; which means developers have to invest a significant amount of time to comprehend the code.

In order to avoid this this, I use PHP’s sprintf() function. sprintf() is a function that’s part of a family of functions –referred to as the “printf” family of function– that substitute designated tokens with arguments to the function. For example, let’s look at the code in example 3.2.
Example 2: Cleanly Assembled String With sprintf()

<?php

$sql = ‘SELECT col1, col2, col3 ‘ .
‘FROM people ‘ .
‘WHERE first_name = “%s” ‘ .
‘AND last_name = “%s” ‘ .
‘AND foo = “%s” ‘ .
‘ORDER BY col1 ‘;

$sql = sprintf($sql, mysql_real_escape_string($first_name),
mysql_real_escape_string($last_name),
($bar = “good” ? “good” : “bad”));

?>

This method allows developers to regain a sense of the data that they’re representing. In this particular example the %s token means replace with a string. There a number tokens such as %d (decimal) and %f (floating point).

Archive Effectively

Thursday, June 19th, 2008

The best archives are carefully organized into subjects and date ranges. For search traffic (particularly long tail terms), it can be best to offer the full content of every post in a category on the archive pages, but from a usability standpoint, just linking to each post is far better (possibly with a very short snippet). Balance these two issues and make the decision based on your goals. A last note on archiving - pagination in blogging can be harmful to search traffic, rather than beneficial (as you provide constantly changing, duplicate content pages). Pagination is great for users who scroll to the bottom and want to see more, though, so consider putting a “noindex” in the meta tag or in the robots.txt file to keep spiders where they belong - in the well-organized archive system.
-

How To Change A Cmos Battery

Wednesday, June 18th, 2008

The inside of a computer is a bad place full of electricity and sharp edges. On the electricity side always when working on you computer make sure that it’s still plugged in to the power socket and the power is turned off, this is to ensure that any static From you is discharged through the earth. The inside of most computer cases are unfinished metal and has very sharp edges so be careful.

The first signs of a battery failing are:-

1) your clock starts running slowly
2) when you boot (start) your computer it has a problem finding your hardware (no hard drive, no cd rom)

To change the battery you need the following tools:-

1) a X-point screwdriver
2) an anti-static strap(optional)
3) a new battery (seems logical)

Then unplug all the cables from the back of the computer as you remove them make a note where they came from. (So when you finished you can put them back)

Move the computer somewhere where you can work on it with ease

Remove the cover by locating the screws around the outer edge (back) of the computer
Some computer cases only require you to remove 2 screws on one side then a panel can be removed allowing you access to the computers insides, others you must remove 6 screws and remove the whole case by sliding it to the rear and lifting it off.

Now make sure that you read the safety instructions about static.
Look inside you will see a round silver thing that looks about the size of a 10p piece (quarter). This is the battery itself, carefully lift the retaining clip and slide the battery out. That’s it removed now go to your local computer retailer, electrical retailer (Tandy/Radio shack) taking the old battery with you and get a new battery.

Back to your computer insert the new battery by lifting the clip and sliding the battery in.

Reinstall your case and plug all the cables back (you did remember to label them didn’t you)

Now for the fun part.

You will now need to go into you bios….

Right the bios is the god of your computer.

To access it, when your computer first starts you will see a black screen with white text.

If you look carefully you will see a line that says something like “press del for setup” or some other key (F2 or ESC or tab) this will take you to god’s house where you can make lots of changes to the way your machine works.

It is also the place where you can make your nice computer in to a rather expensive door stop so be careful and don’t go playing with anything.

You will now be presented with a blue screen with a lot of options on it,
The one we want is load optimized/default settings.

Press the F10 key and type y the computer should now reboot.

If every thing went well then your computer will now be up and running.

Data Capacity of CDs

Wednesday, June 18th, 2008

Abstract
You can fit on a S/VCD without overburning:
- approx. 735 MB of MPEG data onto a 74min/650MB disc
- approx. 795 MB of MPEG data onto an 80min/700MB disc

You can fit on a CD-ROM without overburning:
- approx. 650 MB of data onto a 74min/650MB disc
- approx. 703 MB of data onto an 80min/700MB disc

—————————————————————-

VCD stands for ‘Video Compact Disc’ and basically it is a CD that contains moving pictures and sound. If you’re familiar with regular audio/music CDs, then you will know what a VCD looks like. A VCD has the capacity to hold up to 74/80 minutes on 650MB/700MB CDs respectively of full-motion video along with quality stereo sound. VCDs use a compression standard called MPEG to store the video and audio. A VCD can be played on almost all standalone DVD Players and of course on all computers with a DVD-ROM or CD-ROM drive with the help of a software based decoder / player.

SVCD stands for “Super VideoCD”. A SVCD is very similiar to a VCD,it has the capacity to hold about 35-60 minutes on 74/80 min CDs of very good quality full-motion video along with up to 2 stereo audio tracks and also 4 selectable subtitles. A SVCD can be played on many standalone DVD Players and of course on all computers with a DVD-ROM or CD-ROM drive with the help of a software based decoder / player. It is also possible to use menus and chapters, similiar to DVDs, on a SVCD and also simple photo album/slide shows with background audio. The quality of a SVCD is much better than a VCD, especially much more sharpen picture than a VCD because of the higher resolution. But the quality depends how many minutes you choose to store on a CD, less minutes/CD generally means higher quality.

—————————————————————-

Introduction
Let us ignore for now the terms of megabyte for CD capacity and try to understand how the data is stored on a CD.

As well all know, the data is stored digitally as binary data. This means, however the actual information is actually kept on the disc, this information is in the form of “1″s and “0″s. Physically, the information on a CD is as pits on a thin sheet of metal (aluminium).

An a CD-R disc, the data is physically on an organic dye layer which simulates the metal layer on a real pressed CD.

—————————————————————-

How is the information structured
Now, on the CD, the information isn’t just organised from beginning to end willy-nilly. Otherwise, it would be really hard to find a useful piece of information on the CD.

Rather, the information is organised in sectors. Consider a sector as like a page in a book. Just like you are able to quickly find something in a book if you know the page number, you can quickly find something on a CD if you know the sector number.

Now, remember that the CD was original made to hold audio data. It was decided, that the CD would would 75 sectors per second of audio. Although I cannot guess where this number comes from, it is quite appropriate for the audio CD. It means that you can “seek” an audio CD accurately to 1/75th of a second — which is more than enough for consumer purposes.

Now, with this in mind, we can work out the total data capacity of user data for 1 sector.

—————————————————————-

The total data capacity of user data of 1 sector on a CD
CD audio uses uncompressed PCM stereo audio, 16-bit resolution sampled at 44.1 kHz.

Thus 1 second of audio contains:
16 bits/channel * 2 channels * 44100 samples/second * 1 second
= 1411200 bits
= 176400 bytes

Since there are 75 sectors per second
1 sector
= 176400 bytes / 75
= 2352 bytes

One sector on a CD contains 2352 bytes max.

—————————————————————-

The concept of different MODES and FORMS of burning
Now, audio CD was well and good, but the medium would become much more useful if you could store other data on the disc as well. This became to be know as CD-ROM of course.

Now, the audio-CD uses the ENTIRE sector for audio data.

However, for CD-ROMs this caused a problem. Simply, CDs and the CD reading mechanisms were not 100% faultless. That is, errors (indeed frequent errors) could be made during the reading. For audio CDs, this does not matter as much as you could simply interpolate from the adjacent audio samples. This will obviously NOT DO for data CDs. A single bit error could lead to a program being unexecutable or ruin an achive file.

Thus, for CD-ROMs, part of each sector is devoted to error correction codes and error detection codes. The CD-R FAQ has the details, but in effect, only 2048 bytes out of a total of 2352 bytes in each sector is available for user data on a data CD.

This burning mode is either MODE1 or MODE2 Form1.

—————————————————————-

MODE2 Form2 sectors of VCDs and SVCDs
Now, for VCDs and SVCDs, the video tracks do not necessarily require the robust error correction as normal data on a CD-ROM. However, there is still some overhead per sector that is used for something other than video data (e.g., sync headers).

S/VCDs video tracks are burnt in what is called MODE2 Form2 sectors. In this mode, only 2324 bytes out of a total of 2352 bytes in each sector is available for user data.

This is MUCH MORE than for CD-ROMs, but still less per sector than audio CD.

—————————————————————-

The disc capacities of CD-ROMs, audio-CDs and VCDs
Now, obviously what ultimately determines the capacity of a disc is the total number of sectors it contains. This is similar to the total number of pages in a blank exercise book (if you recall the book analogy).

The secondary determinant is the burning mode of the disc.

For audio CDs, it is as if you could fill each page from top to bottom with audio data as the entire sector is used for audio data.

For CD-ROMs, it is as if you need to first rule a margin and then leave the bottom part of each page for footnotes (headers + ECC + EDC). The amount of text you can actually write per page is then less due to these other constraints.

For S/VCDs, we still need to rule a margin on the page, but we don’t have to worry about the footnotes (headers). We can fit MORE text than a CD-ROM, but less than an audio-CD.

Now remember, 1 second on a CD = 75 sectors.

Thus:
- 74 min CD = 333,000 sectors
- 80 min CD = 360,000 sectors

Data capacity in Mb for an audio-CD
74 min
= 333,000 sectors * 2352 bytes / sector
= 783216000 bytes
= 746.9 Mb

80 min
= 360,000 sectors * 2352 bytes / sector
= 846720000 bytes
= 807.5 Mb

Data capacity in Mb for a CD-ROM
74 min
= 333,000 sectors * 2048 bytes / sector
= 681984000 bytes
= 650.4 Mb

80 min
= 360,000 sectors * 2048 bytes / sector
= 737280000 bytes
= 703.1 Mb

Data capacity in Mb for a S/VCD
74 min
= 333,000 sectors * 2324 bytes / sector
= 773892000 bytes
= 738.0 Mb

80 min
= 360,000 sectors * 2324 bytes / sector
= 836640000 bytes
= 797.9 Mb

—————————————————————-

Conclusions
As you can see, the often quoted capacities of 650MB and 700MB refer to CD-ROM capacities.

Due to the fact that S/VCDs use a different burning mode where MORE of each sector is available as user data, the relatively capacities are HIGHER.

Now, since S/VCDs are not composed of PURELY video tracks and have some unavoidable overheads, the actually total capacity left for video tracks is a few Mb less for each disc (about 735 Mb for 74min discs and 795 Mb for 80min discs). This is where the often quoted capacities of 740MB and 800MB come from. They are quite accurate.

All these capacities are available BEFORE overburning. Overburning is where you burn MORE sectors than the disc is rated for. If you overburn, you can typically achieve about 1-2 minutes of additional capacity (depending on your drive and media).