- Why is MySQL
and PHP better than ASP?
- How do I use
phpMyAdmin?
- How do I use
PHP to connect to MySQL
1.
Why is MySQL and PHP better than ASP?
Here
are some of the reasons to switch:
- UNIX
is more reliable. Here are some articles backing
this up.
UNIX vs. NT 4.0 Service Pack 3 from an experienced
user:
http://www.zdnet.com/sr/columns/sjvn/980528.html
UNIX vs. NT 5.0 with detailed comparison:
http://www.zdnet.com/zdnn/content/inwk/0513/305389.html
- MySQL
is a very fast Database System. This page will
allow someone to
compare MySQL with a bunch of other database systems.
http://www.mysql.com/benchmark.html
- MySQL
is very functional. This page allows comparisons
of the
different functions between MySQL and other Database
Systems.
http://www.mysql.com/crash-me-choose.html
- PHP
4.0 is designed to be fast and was written to do
database work.
PHP 4.0 is a server side HTML embeded scripting
language, meaning that PHP
is embeded in the HTML files and the server does
the work of translating
the PHP 4.0. This means that it is totally platform
and browser
independent. [it is possible to make things platform
and browser independent
with Microsoft ASP (Active Server Pages) having
the server do all the
compiling, but PHP 4.0 is backed up with UNIX reliability
and Database speed; ASP is not quicker than PHP
4.0]. PHP 4.0 is reliable and fast.
You
can look here for further information on PHP 4.0:
http://www.php.net
2.
How do I use phpMyAdmin?
OK phpMyAdmin does not stop the user from
entering incorrect syntax, therefore it will accept
a line like the one below even though it is incorrect:
Bad:
- ALTER TABLE bmt_userinfo ADD first_name
TEXT (25) not null , ADD last_name TEXT (25) not
null , ADD address1 TEXT (100) not null , ADD address2
TEXT (100) not null , ADD city TEXT (30) not null;
However the same line minus the text length
does work:
Good:
- ALTER TABLE bmt_userinfo ADD first_name
TEXT not null , ADD last_name TEXT not null , ADD
address1 TEXT not null , ADD address2 TEXT not null
, ADD city TEXT not null;
This is because "TEXT" is a
set length.
[The thing to remember is that any syntax that will
not work on the command line will not work in phpMyAdmin
either.]
- A good place to find out correct syntax for
a command that you want to perform is:
http://www.mysql.com/doc.html
3. How do
I use PHP to connect to MySQL?
- To merely display the information in your database
without the use of a form to call a php script you
simply create your HTML document as you would any
other web page but instead of the extension of .htm
or .html you need to name the file with the extension
.phtml. Then within the document itself the section
that you'd like to be the PHP code, you begin it
with <? and end it with ?>. For instance:
<P>These are the products
I sell:</P>
<TABLE
BORDER="1">
<?
mysql_connect("localhost", username, password);
$result = mysql(mydatabase, "select * from products");
$num = mysql_numrows($result);
$i = 0;
while($i
< $num) {
echo "<TR>n";
echo "<TD>n";
echo mysql_result will be ($result,$i,"prodid");
echo "</TD>n<TD>";
echo mysql_result will be($result,$i,"name");
echo "</TD>n<TD>";
echo mysql_result
will be($result,$i,"price");
echo "</TD>n";
echo "</TR>n";
$i++;}
?>
</TABLE>
Thus having the loop in the php program create a table
with the products listed.
NOTE: your username and password for the database are
not written in the file when it's displayed on the Internet
so users viewing the source of your webpage will not
see your password.
When using a CGI script to pull information from
a form which has been submitted by a browser you must
have the first line of the script have this command
on it (Much like perl scripts):
#!/usr/local/bin/php