note 112144 added to classobj.examples
| From: | hafiz at bhuiyansoft dot com | Date: | Fri, 10 May 2013 06:15:19 +0000 |
| Subject: | note 112144 added to classobj.examples | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-194755@lists.php.net to get a copy of this message | ||
<?php
/**
* Description of bsdb class for database handle
* @author BhuiyanSoft
*/
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);
}
}
?>
----
Server IP: 69.147.83.199
Probable Submitter: 180.149.25.87
----
Manual Page -- http://php.net/manual/en/classobj.examples.php
Edit -- https://master.php.net/note/edit/112144
Del: integrated -- https://master.php.net/note/delete/112144/integrated
Del: useless -- https://master.php.net/note/delete/112144/useless
Del: bad code -- https://master.php.net/note/delete/112144/bad+code
Del: spam -- https://master.php.net/note/delete/112144/spam
Del: non-english -- https://master.php.net/note/delete/112144/non-english
Del: in docs -- https://master.php.net/note/delete/112144/in+docs
Del: other reasons-- https://master.php.net/note/delete/112144
Reject -- https://master.php.net/note/reject/112144
Search -- https://master.php.net/manage/user-notes.php