| |
PHP is a powerful server-side scripting language, using commands embedded in html. It can communiate directly with a MySQL database.
Because of the insecure nature of mod_php3, we support php as CGI instead. To use a standard *.php file, you need to add one line at the top:
#!/usr/local/bin/php
and follow all the other steps for CGI scripts (use ASCII mode ftp, and make it executable by setting permissions to mode 700).
An example of a simple php3 test script
#!/usr/local/bin/php
<?php phpinfo()?>
An example of communicating with a MySQL database
Note: you must change the port "12345" to match the tcp port your MySQL server listens on.
#!/usr/local/bin/php
<?
$conn=mysql_connect("127.0.0.1:12345");
if(!mysql_select_db("test",$conn)){echo ("Cannot select database.\n");}
$sql="create table phptest (php char(20), test char(20))";
if(!mysql_query($sql,$conn))
{
echo ("Error creating test table.\n");
}else{
echo ("test table created.\n");
}
$sql="insert into phptest values('this is a','test insert')";
if(!mysql_query($sql,$conn))
{
echo ("Error Inserting data into test table.\n");
}else{
echo ("Data inserted to test table.\n");
}
$sql="select * from phptest";
if(!($result=mysql_query($sql,$conn)))
{
echo ("Error selecting data from test table.\n");
}else{
echo ("Data selected from test table.\n");
while(($data=mysql_fetch_row($result))){
echo("$data[0] $data[1]\n");
}
}
$sql="delete from phptest where test like 'test%'";
if(!mysql_query($sql,$conn))
{
echo ("Error deleting data from test table.\n");
}else{
echo ("Data deleted from test table.\n");
}
if(!mysql_query($sql,$conn))
{
echo ("Error Inserting data into test table.\n");
}else{
echo ("Data inserted to test table.\n");
}
$sql="drop table phptest";
if(!mysql_query($sql,$conn))
{
echo ("Error deleting test table.\n");
}else{
echo ("test table deleted.\n");
}
mysql_close($conn);
?>
For more information on programming with PHP, please see the official documentation here.
|