Starting Out
The first thing we need to do is verify that the two major components of this tutorial are working correctly. If you do this now, it will rule out a whole host of potential errors when you are attempting to debug the minor scripts written in this tutorial. "Hello World" has got to be one of the most maligned programs in the world. (Aside from various Microsoft's products.) It is exceedingly simplistic to write and does little. What it does prove however is that the basic workings of PHP are up and running. Create a file called <html> <body> <? echo("Hello World\n"); ?> </body> </html> When you view that file on your web server, you should see a single line saying: Hello World. If you do, then PHP is working correctly working. 2.2 Creating a test table in MySQL I'm assuming that you have telnet access to a machine which can connect to the MySQL server. If you do not, it is still possible to create and manipulate database on a remote server through Perl and the DBI interface, however that is outside the bounds of this small tutorial. Connect to your MySQL database server and create a test database and the test table that we'll use for this tutorial. %> mysql -uUSERNAME -pPASSWORD mysql> create database phptest; Query OK, 1 row affected (0.13 sec) mysql> create table TEST -> ( -> ID int auto_increment primary key, -> Name varchar(32), -> Age int, -> Salary int -> ); Query OK, 0 rows affected (0.11 sec) Using 2.3 Adding information to the test table Now we'll add a bunch of rows to the table so we'll have something to play with when we try to access this database via PHP. mysql> insert into TEST values (0,'Billy Bob Barker','87','93000'); Query OK, 1 row affected (0.09 sec) mysql> insert into TEST values (0,'Sniffling Sam Sloth','23','12000'); Query OK, 1 row affected (0.01 sec) mysql> insert into TEST values (0,'Roy Bartley','31','87000'); Query OK, 1 row affected (0.01 sec) mysql> insert into TEST values (0,'Leroy Longrad','45','63000'); Query OK, 1 row affected (0.01 sec) mysql> insert into TEST values (0,'Amy Antwerp','37','34000'); Query OK, 1 row affected (0.01 sec) mysql> insert into TEST values (0,'Kim Kruger','57','76000'); Query OK, 1 row affected (0.01 sec) The resulting table data should look like: mysql> select * from TEST; +----+---------------------+------+--------+ | ID | Name | Age | Salary | +----+---------------------+------+--------+ | 1 | Billy Bob Barker | 87 | 93000 | | 2 | Sniffling Sam Sloth | 23 | 12000 | | 3 | Roy Bartley | 31 | 87000 | | 4 | Leroy Longrad | 45 | 63000 | | 5 | Amy Antwerp | 37 | 34000 | | 6 | Kim Kruger | 57 | 76000 | +----+---------------------+------+--------+ 6 rows in set (0.16 sec) 2.4 Connecting to the database with PHP Now that we know that PHP is working and there is information ready
and waiting in the database, it's time to tie them both together. Save
the PHP class code to a file called
" Create a new file, " <html> <body> <? require("util.php3"); $sql = new MySQL_class; $sql->Create("phptest"); echo("Database connection successful.\n"); ?> </body> </html> Loading this file into your browser, you should see | ||
![]() |
![]() |
![]() |
Vt. Web Wizard Home | Email Questions & Comments
© 1998 Vt. Web Wizard