hkhosting.com

instructions to users

HOME
support/ change password | F.A.Q. | glossary
about us
technical specs
payment methods
contact us
hosting packages
server hosting
sign up
special offers
resellers
domain availability
jump to another section
Index

php

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_php, we support php as CGI instead. To use a standard *.php file, you need to add one line at the top of each php file (excluding php files that are included from another php):

For PHP4, add #!/usr/local/bin/php
For PHP5, add #!/usr/local/bin/php5

and follow all the other steps for CGI scripts.

Please make sure that you upload all PHP files using ASCII mode and make them executable by setting permissions to mode 700 or 755.

An example of a simple php 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.

Copyright © 2023homeWhat Next Limited. All rights reserved. Quality Hong Kong web hosting. | Feedback | Terms & Conditions