Okay the above explains some basic syntax of coding PHP/MySQL pages. Now lets get started. we are going to make a search engine.
first will will need to log in to our database and create the tables we need. Assuming you have an SSH or telnet client(if not try
putty ) open it up. Now set it up to login to your server. I will only say this, if you have SSH as an option to connect you should use it instead of telnet. That is another lesson. Any knowlegeable person feeling like doing this lesson I will put a link here if your do it.
So you are now connected to your server via telnet or SSH. From this point on the command prompt will be "$".
You should now be looking at something like what I have below.
SunOS 5.7
Last login: Tue Jun 28 14:47:43 from 199.*.*.*
Sun Microsystems Inc. SunOS 5.7 Generic October 1998
You have mail.
$
Notice this is from a Sun Microsystems OS, you may have windown, Linux, BSD, who knows. I am using Sun Solaris. I said something like this not exactly what I have. It is the command prompt we are worried about.
Above you see my login. Lets take a look. The command is "mysql". Then you use the attribute "-u". Lets look at all atributes shall we.
mysql Ver 11.18 Distrib 3.23.52, for sun-solaris2.7 (sparc)
Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL license
Usage: mysql [OPTIONS] [database]
-?, --help Display this help and exit.
-A, --no-auto-rehash No automatic rehashing. One has to use 'rehash' to
get table and field completion. This gives a quicker
start of mysql and disables rehashing on reconnect.
-B, --batch Print results with a tab as separator, each row on
a new line. Doesn't use history file.
--character-sets-dir=...
Directory where character sets are located.
-C, --compress Use compression in server/client protocol.
-D, --database=.. Database to use.
--default-character-set=...
Set the default character set.
-e, --execute=... Execute command and quit. (Output like with --batch)
-E, --vertical Print the output of a query (rows) vertically.
-f, --force Continue even if we get an sql error.
-g, --no-named-commands
Named commands are disabled. Use \* form only, or
use named commands only in the beginning of a line
ending with a semicolon (;) Since version 10.9 the
client now starts with this option ENABLED by
default! Disable with '-G'. Long format commands
still work from the first line.
-G, --enable-named-commands
Named commands are enabled. Opposite to -g.
-i, --ignore-spaces Ignore spaces after function names.
-h, --host=... Connect to host.
-H, --html Produce HTML output.
--local-infile=[1|0] Enable/disable LOAD DATA LOCAL INFILE
-L, --skip-line-numbers
Don't write line number for errors.
--no-pager Disable pager and print to stdout. See interactive
help (\h) also.
--no-tee Disable outfile. See interactive help (\h) also.
-n, --unbuffered Flush buffer after each query.
-N, --skip-column-names
Don't write column names in results.
-O, --set-variable var=option
Give a variable an value. --help lists variables.
-o, --one-database Only update the default database. This is useful
for skipping updates to other database in the update
log.
--pager[=...] Pager to use to display results. If you don't supply
an option the default pager is taken from your ENV
variable PAGER ().
Valid pagers are less, more, cat [> filename], etc.
See interactive help (\h) also. This option does
not work in batch mode.
-p[password], --password[=...]
Password to use when connecting to server
If password is not given it's asked from the tty.
-P, --port=... Port number to use for connection.
-q, --quick Don't cache result, print it row by row. This may
slow down the server if the output is suspended.
Doesn't use history file.
-r, --raw Write fields without conversion. Used with --batch
-s, --silent Be more silent.
-S --socket=... Socket file to use for connection.
-t, --table Output in table format.
-T, --debug-info Print some debug info at exit.
--tee=... Append everything into outfile. See interactive help
(\h) also. Does not work in batch mode.
-u, --user=# User for login if not current user.
-U, --safe-updates[=#], --i-am-a-dummy[=#]
As you can see we have a few options here. We are mainly intrested in -u and -p. "-u" to type in your user name. -p is for your password. See example below.
Last login: Mon Aug 15 14:58:05 from 199.*.*.*
Sun Microsystems Inc. SunOS 5.7 Generic October 1998
$ mysql -uUSER_NAME -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 230981 to server version: 3.23.52
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>
I have never had luck typing my password after "-p". I hit enter and it will prompt me for the password. Do this step and you should see the MySQL prompt. You should also see the clouds part and hear angles harps. Welcome to heaven. Or as I call it MySQL. Do you feel the power you now have? If not you will. You will...
Once you see the "mysql>" prompt you can start to Create databases, Create tables, edit tables, databases, blah blah blah.... First command you will need is kind of tough. Assuming you are starting from scratch(instalation is also another tutorial). What we want to do is Create a Database.
mysql> CREATE DATABASE New_database
-> ;
Query OK, 1 row affected (0.09 sec)
mysql>
Above we see the command. The command is "CREATE DATABASE" see
http://dev.mysql.com/doc/mysql/en/create-database.html for more info on this function. You use it like so(well if you have rights to use it).
mysql> CREATE DATABASE db_name_here
^ ^ ^
prompt command the name you assign to your new database
Pretty tough right? Yea sure. Now you can do this in PHP, but that would be just stupid so I am not writing about it. That is a security risk you do not need to take.
Next up we need to create a table. Think of a table like a spead sheet or like excel. You have colums and rows. So we are building a search engine, lets think how we want to lay out our table. Well I will think you will suck up my thinking.
We will need a colum for each of the following.
1.) Page URL
2.) Page description
3.) Page title
4.) keyword 1
5.) keyword 2
6.) keyword 3
7.) keyword 4
8.) keyword 5
9.) id
Now this is a very simple table. The first thing we have to do is figure out our data types
http://dev.mysql.com/doc/mysql/en/column-type-overview.html For now we will focus on a few data types
CHAR,
VARCHAR,
TEXT,
INT,
BLOB
The "char" and "varchar" data types:
Please see the MySQL page on them.
http://dev.mysql.com/doc/mysql/en/char.html It explains what the main differences are. for us either will do.
The length of a CHAR column is fixed to the length that you declare when you create the table. The length can be any value from 0 to 255. (Before MySQL 3.23, the length of CHAR may be from 1 to 255.) When CHAR values are stored, they are right-padded with spaces to the specified length. When CHAR values are retrieved, trailing spaces are removed.
Values in VARCHAR columns are variable-length strings. The length can be specified as 1 to 255 before MySQL 4.0.2, 0 to 255 as of MySQL 4.0.2, and 0 to 65,535 as of MySQL 5.0.3. (The maximum actual length of a VARCHAR in MySQL 5.0 is determined by the maximum row size and the character set you use. The maxim
The "blob" and "text" data types:
Please see the MySQL page on them
http://dev.mysql.com/doc/mysql/en/blob.html BLOB columns are treated as binary strings (byte strings). TEXT columns are treated as non-binary strings (character strings). BLOB columns have no character set, and sorting and comparison is based on the numeric values of the bytes in column values. TEXT columns have a character set, and values are sorted and compared based on the collation of the character set assigned to the column as of MySQL 4.1. Before 4.1, TEXT sorting and comparison are based on the collation of the server character set.
That leave "int", if you do not know this one go back to learning PHP basics as you are not ready for MySQL integration yet. "int" is numeric. That is to say, it is for numbers. There are other datatypes for numbers but I am lazy and you are getting a free ride. But to read up more on numeric values check out.
http://dev.mysql.com/doc/mysql/en/numeric-types.html Now that we have that done we will lay out table
1.) URL VARCHAR(255)
2.) description TEXT
3.) Page title VARCHAR(100)
4.) keyword 1 VARCHAR(25)
5.) keyword 2 VARCHAR(25)
6.) keyword 3 VARCHAR(25)
7.) keyword 4 VARCHAR(25)
8.) keyword 5 VARCHAR(25)
9.) id int(11) AUTO_INCREMENT PRIMARY KEY
What are those numbers? varchar(100) means this colum will have
up to 100 charaters or places for charaters. I will have to finish this later. Time to go home.