PHP Developing Guide


Even if nowadays most of web php application are written using various frameworks, or platforms for a beginner i consider that first of all he should learn to develop application in pure PHP code. For those who continue to develop, web application using pure PHP code i present below some usefull functions/ piece of code used in developing php application from scratch. 1. Function that connect to db.

private function connect_db(){
    if ($dbc=@mysql_connect('host','username','password'))      // make connection
        if (!@mysql_selectdb('dbname')) // select db
            die ('I can not select db: <b>'.mysql_error().'</b>'); 
    } else{ 
       die('Connection fail: <b>'.mysql_error().'</b>'); 
    return $dbc; 


2. Function to send email in html format:


public function send_mail($subject, $content){
     $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
     $headers .= 'From: MySelf <>' . "\r\n";
     @mail('', $subject, nl2br($content), $headers);       

3. Function to get user from db:

public function get_user($id){
  $query= "SELECT * FROM users_table WHERE id_user = '$id'";
  return $rez; 

Add comment