Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- * Klasė C-main 1.0.1
- * Sukurta : 2011.06.08
- * Autorius : Aurimas Gerčas
- */
- class cmain {
- /* naudojama insert */
- private $insert_first = array();
- private $insert_last = array();
- private $back = array();
- public function __construct($host, $user, $pass, $db) {
- $this->host = $host;
- $this->user = $user;
- $this->pass = $pass;
- $this->db = $db;
- $this->link = mysql_pconnect("$this->host","$this->user","$this->pass");
- mysql_select_db($this->db,$this->link) or die (mysql_error());
- }
- public function insert($tbl,$data) {
- $this->tbl = $tbl;
- foreach ($data as $name=>$value)
- {
- $this->insert_first[] = $name;
- $this->insert_last[]= $value;
- $this->back[$name] = $value;
- }
- $this->insert_first = '(`'.implode('`,`',$this->insert_first).'`)';
- $this->insert_last = "(".implode(",",$this->insert_last).")";
- mysql_query("INSERT INTO `$this->tbl` $this->insert_first VALUES $this->insert_last ");
- //echo "INSERT INTO $this->tbl $this->insert_first VALUES $this->insert_last";
- return ($this->back);
- }
- public function update ($tbl,$where,$data){
- $this->where = array();
- foreach ($where as $key=>$value){
- $this->where[] = "$key = $value";
- }
- $this->where = implode (' AND ', $this->where);
- /* foreach sudarantis update */
- foreach ($data as $key=>$value){
- $this->update[] = "`$key` = $value";
- }
- $this->update = implode (',',$this->update);
- mysql_query("UPDATE `$tbl` SET $this->update WHERE $this->where");
- //echo "UPDATE `$tbl` SET $this->update WHERE $this->where";
- }
- public function select ($tbl,$where){
- $this->where = array();
- foreach ($where as $key=>$value){
- $this->where[]= "`$key` = $value";
- }
- $this->where = implode (' AND ', $this->where);
- if (empty($this->where)){
- $result = mysql_query("SELECT * FROM `$tbl`",$this->link);
- }
- if (!empty ($this->where)){
- $result = mysql_query("SELECT * FROM `$tbl` WHERE $this->where");
- }
- while ($row = mysql_fetch_array( $result )) {
- $this->back[] = $row ;
- }
- return ($this->back);
- }
- public function delete ($tbl,$where){
- $this->where = array();
- foreach ($where as $key=>$value){
- $this->where[]= "`$key` = $value";
- }
- $this->where = implode (' AND ', $this->where);
- $result = mysql_query("DELETE FROM $tbl WHERE $this->where");
- }
- public function num_rows ($tbl, $where){
- $this->where = array();
- foreach ($where as $key=>$value){
- $this->where[]= "`$key` = $value";
- }
- $this->where = implode (' AND ', $this->where);
- $result = mysql_query("SELECT * FROM $tbl WHERE $this->where");
- $rows = mysql_num_rows($result);
- return ($rows);
- }
- public function search($tbl, $fields){
- $this->where = array();
- foreach ($fields as $key=>$value){
- if (empty($value)) continue;
- $this->where[]= "`$key` = '$value'";
- }
- $this->where = implode (' AND ', $this->where);
- $result = mysql_query("SELECT * FROM $tbl WHERE $this->where");
- //echo "SELECT * FROM $tbl WHERE $this->where";
- while ($row = mysql_fetch_array( $result )) {
- $this->back[] = $row ;
- }
- return ($this->back);
- }
- public function __destruct() {
- mysql_close($this->link);
- }
- }
- $obj = &new cmain(host, user, pass, db);
- $obj1 = &new cmain(host, user, pass, db);
- $obj2 = &new cmain(host, user, pass, db);
- $obj3 = &new cmain(host, user, pass, db);
- $obj4 = &new cmain(host, user, pass, db);
- $obj5 = &new cmain(host, user, pass, db);
- $obj6 = &new cmain(host, user, pass, db);
- $obj7 = &new cmain(host, user, pass, db);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement