Advertisement
Guest User

Untitled

a guest
Aug 20th, 2016
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. <?php
  2.  
  3. //class Database
  4. class Database
  5. {
  6. private $username;
  7. private $pass;
  8. private $server;
  9. private $database;
  10.  
  11.  
  12. public function __construct(){
  13.  
  14. $this->username='root';
  15. $this->pass='';
  16. $this->server='localhost';
  17. $this->database='op_db';
  18. $this->initial_db();
  19.  
  20. }
  21.  
  22. public function initial_db(){
  23.  
  24. $con = mysql_connect($this->server, $this->username, $this->pass) or die( 'unable to connect to database');
  25. $db=mysql_select_db($this->database, $con);
  26. if(!$db)
  27. die('unable to selct db');
  28. }
  29.  
  30. public function insert($row){
  31.  
  32. for($i=0;$i<count($row);$i++){
  33.  
  34. $status = 2;
  35. $remoteAddr = 0;
  36. $query = "INSERT INTO tbl_item_events SET publish_date = '".date("Y-m-d H:i:s")."', approved_date = '".date("Y-m-d H:i:s")."', user_id = '300'";
  37. $query.= ", creation_date='".date("Y-m-d H:i:s")."', status= '".$status."', ip_address ='".$remoteAddr."'";
  38.  
  39. foreach($row[$i] as $key => $value)
  40. {
  41. $query.=", ".$key."='".$value."' ";
  42. }
  43.  
  44. if($this->avoid_redundace($row[$i]['title'],$row[$i]['description'],$row[$i]['address'],$row[$i]['expire_date'],$row[$i]['item_birth_date']))
  45. $result= mysql_query($query);
  46.  
  47.  
  48. // $item_id = mysqli_insert_id($con);
  49.  
  50. //$insertCatTable = "insert into item_categories_business(`item_id`,`category_id`,`p1`,`p2`,`p3`,`itemLat`,`itemLon`) values(".$item_id.",".$item_category.",".$p1.",".$p2.",".$p3.",".$item_lat.",".$item_lon." )";
  51. // mysqli_query($con, $insertCatTable);
  52.  
  53. }
  54.  
  55.  
  56. }
  57.  
  58. public function avoid_redundace($title,$des,$add,$exp,$birth){
  59.  
  60. $query='SELECT title FROM tbl_item_events WHERE title="'.$title.'"'; //AND description="'.$des.'" AND address="'.$add.'" AND expire_date="'.$exp.'" AND item_birth_date="'.$birth.'"';
  61. $result= mysql_query($query);
  62. $count=mysql_fetch_array($result);
  63. if(mysql_num_rows($count)>0)
  64. return FALSE;
  65. return TRUE;
  66.  
  67. }
  68.  
  69.  
  70.  
  71. }
  72. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement