0
Posted November 10, 2012 by Bandish Patel in PHP
 
 

ClassPhp Version 1.0 [OpenSource PHP Class management software]


ClassPHP 1.0 LOGO

ClassPHP 1.0

[OpenSource PHP Class management software]

Today,We learn about how to create your own reusable class file using php script.In this class file provide all function that was used.

In this class file provide this facilities :

Sno     Facilities In classfile

1          Insert Record
2          Delete Record
3          Delete All Record
4          Update Record
5          Login Authenticate
6          Logout Authenticat
7          Union All
8          Upload image
9          Error Msg
10         Select All record
11         Select One Record
12         Count All Record
13         count One Record
14         Logout
15         Session Class
16         connection
This is really amazing classfile code.its very helpful to all developer.Here we can describe all details about this php class file.

Implementation in project:

  1.  configure database setting to the classfile:
  2.  add class file whenever you can use.
  3.  create object of this class.
    • ex:   $vzr=new classname();
  4.  apply method.
    • EX:.  $c=new classname();
    • $table=”tablename”;
    • $data=use database field for insert;
    • $post=add post field data
    • $data[]=$_post[”];
    • $add=$c->insert($table,$data);

Finally the class file :

class myquery{
function __construct()

{

$c=@mysql_connect('localhost','username','password');

@mysql_select_db('dbname',$c);

}

function selectAll($table)

{

$query=mysql_query("select * from $table");

while($res=mysql_fetch_array($query))

{

$data[]=$res;

}

return $data;

}

function selectByAll($table,$field)

{

$query=mysql_query("select * from $table where $field");

while($res=mysql_fetch_array($query))

{

$data[]=$res;

}

return $data;

}

function selectOne($table,$field)

{

$query=mysql_query("select * from $table where $field");

$res[]=mysql_fetch_array($query);

return $res;

}

function DeleteAll($table)

{

$query=mysql_query("delete from $table");

return $query;

}

function DeleteOne($table,$field)

{

$query=mysql_query("delete from $table where $field");

return $query;

}

function Insert($table,$field)

{

$ct=0;

foreach($field as $key=>$value)

{

$ct++;

if(count($field)==$ct){$sp='';}else{$sp=',';}

$allkey=$allkey.$key.$sp;

$allvalue=$allvalue."'".$value."'".$sp;

}

$query=mysql_query("insert into $table($allkey) values ($allvalue)");

return $query;

}

function Update($table,$field,$condition)

{

$ct=0;

foreach($field as $key=>$value)

{

$ct++;

if(count($field)==$ct){$sp='';}else{$sp=',';}

$all=$all            .$key."='".$value."'".$sp;

}

$query=mysql_query("update $table set $all where $condition");

return $query;

}

function CountAllRecord($table)

{

$query=mysql_query("select * from $table");

$row=mysql_num_rows($query);

return $row;

}

function CountByRecord($table,$condition)

{

$query=mysql_query("select count(*) from $table where $condition");

$row=mysql_num_rows($query);

return $row;

}

function UnionAll($table1,$table2)

{

$query=mysql_query("select * from $table1 union select * from $table2");

return $query;

}

function Login($table,$condition)

{

$query=mysql_query("select * from $table where $condition");

return $query;

}

function check_login($table,$condition)

{

$query=mysql_query("select * from $table where $condition");

$row=mysql_num_rows($query);

return $row;

}

function Logout()

{

session_start();

session_unset();

session_destroy();

session_write_close();

setcookie(session_name(),'',0,'/');

session_regenerate_id(true);

header("Location:login.php");

}

function Session_check($data)

{

if($data['id']==NULL)

{

header("Location:login.php");

}

}

function Upload_Image($path)

{

//add your valid file extension

$allowedExts = array("jpg","jpeg","gif","png","txt","pdf","doc","xls","ppt","avi","mp3","zip","docx");

$extension = end(explode(".", $_FILES["file"]["name"]));

if (in_array($extension, $allowedExts))

{

if ($_FILES["file"]["error"]>0)

{

echo "Return Code: " . $_FILES["file"]["error"] . "
";

}

else

{

echo "Upload: " . $_FILES["file"]["name"] . "
";

echo "Type: " . $_FILES["file"]["type"] . "
";

echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb
";

echo "Temp file: " . $_FILES["file"]["tmp_name"] . "
";

if (file_exists($path.$_FILES["file"]["name"]))

{

echo $_FILES["file"]["name"] . " already exists. ";

}

else

{

move_uploaded_file($_FILES["file"]["tmp_name"],$path. $_FILES["file"]["name"]);

echo "Stored in:".$path.$_FILES["file"]["name"];

}

}

}

else

{

echo "Invalid file";

}

}
function error_msg()

{

//you have to apply all your login errors

echo "Please Provide the Correct Details";

}

}

Try For Free:Download Here


Bandish Patel