note 112148 deleted from language.oop5 by googleguy
| From: | googleguy@php.net | Date: | Fri, 10 May 2013 11:06:22 +0000 |
| Subject: | note 112148 deleted from language.oop5 by googleguy | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-194768@lists.php.net to get a copy of this message | ||
Note Submitter: hafiz_fp_bd at yahoo dot com
----
<?php
/* Description of bsdb class for database handle
* @author Md.Hafizur Rahman
* @databse connect
* @data retrive dara from table
* @delete from table
* @insert data into table
* @update data */
class bsdb
{
var $con;
var $sdb;
var $sql;
var $str;
var $value;
var $key;
var $strarr=array();
var $result=array();
public function __construct($server,$db,$user,$pass)
{
$this->con=@mysql_connect($server,$user,$pass) or die(mysql_error());
$this->sdb=@mysql_select_db($db,$this->con) or die(mysql_error());
}
public function getvalue($tbl,$fn=array(),$fcon=array())
{
$this->sql='';
$this->key='';
$this->value='';
$this->result=array();
$this->sql="SELECT ";
for($i=0;$i<count($fn);$i++)
{
if($i==count($fn)-1)
{$this->sql.=$fn[$i].' ';}
else
{$this->sql.=$fn[$i].', ';}
}
$this->sql.='FROM '.$tbl.' WHERE ';
$this->key=array_keys($fcon);
$this->value= array_values($fcon);
for($i=0;$i<count($fcon);$i++)
{
if($i==count($fcon)-1)
$this->sql.=$this->key[$i]."='".$this->value[$i]."';";
else
$this->sql.=$this->key[$i]."='".$this->value[$i]."' AND ";
}
$this->str=mysql_query($this->sql);
while($arr=mysql_fetch_row($this->str))
{
$this->strarr=array();
foreach ($arr as $value)
{
array_push($this->strarr,$value);
}
array_push($this->result,$this->strarr);
}
return $this->result;
}
public function insert($table,$inserts)
{
$this->key='';
$this->value='';
$this->value = array_map('mysql_real_escape_string', array_values($inserts));
$this->key = array_keys($inserts);
return mysql_query("INSERT INTO ".$table."
(
".implode(",", $this->key).") VALUES
('".implode("','", $this->value)."');");
}
public function update($tblname,$setvalue=array(),$convalue=array())
{
$this->sql='';
$this->key='';
$this->value='';
$this->sql='UPDATE '.$tblname.' SET ';
$this->key=array_keys($setvalue);
$this->value= array_values($setvalue);
for($i=0;$i<count($setvalue);$i++)
{
if($i==count($setvalue)-1)
$this->sql.=$this->key[$i]."='".$this->value[$i]."'";
else
$this->sql.=$this->key[$i]."='".$this->value[$i]."', ";
}
$this->sql.=' WHERE ';
$this->value='';
$this->key='';
$this->key=array_keys($convalue);
$this->value= array_values($convalue);
for($i=0;$i<count($convalue);$i++)
{
if($i==count($convalue)-1)
$this->sql.=$this->key[$i]."='".$this->value[$i]."';";
else
$this->sql.=$this->key[$i]."='".$this->value[$i]."' AND ";
}
return mysql_query($this->sql);
}
public function delete($tblname,$condition= array())
{
$this->sql='';
$this->key='';
$this->value='';
$this->sql='DELETE FROM '.$tblname.' WHERE ';
$this->key=array_keys($condition);
$this->value= array_values($condition);
for($i=0;$i<count($condition);$i++)
{
if($i==count($condition)-1)
$this->sql.=$this->key[$i]."='".$this->value[$i]."';";
else
$this->sql.=$this->key[$i]."='".$this->value[$i]."' AND ";
}
return mysql_query($this->sql);
}
public function __destruct()
{
return mysql_close($this->con);
}
}
?>