Posts Tagged ‘database’

What is a Database?

Tuesday, September 30th, 2008

A database is a structure that comes in two flavors: a flat database and a relational database. A relational database is much more oriented to the human mind and is often preferred over the gabble-de-gook flat database that are just stored on hard drives like a text file. MySQL is a relational database.

In a relational structured database there are tables that store data. The columns define which kinds of information will be stored in the table. An individual column must be created for each type of data you wish to store (i.e. Age, Weight, Height).

On the other hand, a row contains the actual values for these specified columns. Each row will have 1 value for each and every column. For example a table with columns (Name, Age, Weight-lbs) could have a row with the values (Bob, 65, 165). If all this relational database talk is too confusing, don’t despair. We will talk about and show a few examples in the coming lessons.

Running PHP and MySQL

Thursday, July 24th, 2008

In order to do some of our tutorials (or program with PHP and MySQL in general) you need to be able to run PHP and MySQL. Although most free hosts do not have PHP and MySQL support there are some that do, and there are also many low cost hosting options available. If you already have hosting and are unsure if you have PHP and MySQL support you should contact your host directly. If you are shopping for hosting be sure that they support PHP and that your package includes at least one MySQL database.

Another option is to install PHP and MySQL directly onto your Windows computer. If you are a Mac user you already have the capability and just need to activate PHP and MySQL.

What is MySQL?

Thursday, July 24th, 2008

MySQL is a relational database system that is used to store information. MySQL can store many types of data from something as tiny as a single character to as large as complete files or graphics. Although it can be accessed by most programing languages, it is often coupled with PHP because they work together with ease.

Information stored in a MySQL database hosted on a web server can be accessed from anywhere in the world with a computer. This makes it a good way to store information that needs the ability to change over time, but also needs to be accessed over the net. Some examples that can utilize MySQL are a web message board or a customer’s shipping status.

SQL is Not C

Thursday, July 24th, 2008

C is the canonical procedural programming language and the greatest pitfall for a programmer looking to show off his database-fu is that he fails to realize that SQL is not procedural (nor is it functional or object-oriented, for that matter). Rather than thinking in terms of data and operations on data one must think of sets of data and relationships among those sets. This usually crops up with the improper use of a subquery:
SELECT a.id,
(SELECT MAX(created)
FROM posts
WHERE author_id = a.id)
AS latest_post
FROM authors a

Since this subquery is correlated, i.e., references a table in the outer query, one should convert the subquery to a join.
SELECT a.id, MAX(p.created) AS latest_post
FROM authors a
INNER JOIN posts p
ON (a.id = p.author_id)
GROUP BY a.id

Mysql-Creating a Derived Data Column

Thursday, July 24th, 2008

Frequently we query our database for a value but then have to always do the same manipulation on it before we can use it. Well it can often be useful to do this “once” in the database and then store the manipulated value in a separate column of the database.

Here is a very simple example
INSERT INTO tbl_name (col1,col2) VALUES(15,col1*3.14159);

Where col2 is set to the value of col1*pi

You could also do more complex calculation/filtering/shortening in your code eg php,ASP etc

Search Engine Elements

Tuesday, July 15th, 2008

The three major elements of a search engines are: the spider, also called the crawler; the index or catalog; and the search engine which displays the results of your query in your browser.

The spider visits your web page, indexes it, and then follows links to other pages within the site. This is sometimes referred to as being “spidered” or “crawled.” The spider returns to the site every so often looking for changes.

The index is a giant database that contains a copy of every web page that the spider finds. When a web page is changed, then this database is updated with the new information.

Sometimes it takes a while for pages or changes to be added to the index. Therefore, a web page may have been “spidered” but not yet “indexed.” Until it is added to the index, it is not available to searches by the search engine.

Search engine software sifts through the millions of pages recorded in the index to find matches to a query and ranks them in the order of what it believes is most relevant. Different search engines often produce very different results.

PHP:Protect your data from user input

Monday, June 30th, 2008

I came to a point where I needed to filter the user input (not just tell the user something like : “The username isn’t in the right format” or “Please choose a valid name for your username”), I mean let him to input in the form anything he wanted too but in the end what we store in the database is his processed input (only A-Z, a-z and 0-9).
I had the Visual Basic and C++ thinking .. I must do that and that and that to get rid of unwanted characters. It was a little time consuming and I was in hurry so I googled and I reached the ereg_replace help page on PHP.net website. Suddenly all became much much easier :D, just write a regular expression (ohh, by the way .. if someone asks I can write a small tutorial on regular expressions) like this : “[^A-Za-z0-9]” and that was it :).

Below is a small example on how to filter (remove all characters except uppercase/lowercase letters and numbers)

1. <?php
2. //our string
3. $str = “nek#$#hbet|20&&07″;
4. $filtered = ereg_replace(”[^A-Za-z0-9]“, “”, $str);
5. print $filtered; // will print ‘nekhbet2007′
6. ?>

PHP is a strong language with a lot of functions that help us to decrease the development time. So before thinking how to do a certain thing just take a look first at www.php.net and see if what you need isn’t already done

PHP:Easy Way to Optimize Database Table

Saturday, June 28th, 2008

dbConnect()
$alltables = mysql_query(”SHOW TABLES”);

while ($table = mysql_fetch_assoc($alltables))
{
foreach ($table as $db => $tablename)
{
C(”OPTIMIZE TABLE ‘”.$tablename.”‘”)
or die(mysql_error());
}
}

SEO : Find the Best Keywords

Thursday, June 26th, 2008

It would be a waste of your time to optimize your website for keywords that are not even being searched for. Therefore you should invest some energy into finding the best keywords. There are several SEO tools available on the Internet to help you find the best keywords. Tip: Don’t be deceived by organizations that require you to register first. The two most popular resources are WordTracker and Yahoo!. Because Yahoo! has a man-made database that truncates plurals, I prefer to use WordTracker (WT).

Below is a screenshot from WT that shows the results you’ll get when doing a query for “putter”. Notice that “golf putters” has the highest search volume with 100 searches in the last 24 hours, yet there are over 100,000 websites to compete against. Using the tool’s Keyword Effectiveness Index (KEI), you’ll be able to see that “custom putter” would have a better chance at higher ranking, since there are only 2,640 competing.

Here’s a key part of the top 10 SEO tips: When using any SEO tool for doing keyword research, start by keeping your searches ambiguous like we did in the example above for “putters”. The results will always return suggestions, sometimes surprising ones that you may not have thought of.

You can get less comprehensive results by using DigitalPoint’s Keyword Suggestion Tool. This SEO tool will give you a summary of information without the KEI. Personally, I like to know how many people are competing before I design a web page.

Google Link Building takes Patience

Saturday, June 21st, 2008

Links are what makes a popular web site even more popular. Google spiders and indexes links just like they spider and index web sites. If Google has spidered and indexed the web site that links to you than you will gain in popularity. With that popularity your web site can move up in the search engines index. Google as far as anyone can tell is updating their links database every 7 to 12 weeks. If you want to find out if a web page that contains your link is in Google’s database type info:www.yoursite.com into the search field and you will see if that page is indexed or not. If it isn’t than naturally that link as it stands today won’t benefit you until it is in the engines database. It’s important to recognize that a good link building campaign is an on-going process that will have positive long-term results.