Advertisement
Guest User

Untitled

a guest
Jun 30th, 2017
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.71 KB | None | 0 0
  1. <?php
  2. class miqDB {
  3. // single instance of self shared among all instances
  4. private static $instance = null;
  5.  
  6. // db connection config vars
  7. private $user = "miq_sys";
  8. private $pass = "monkey";
  9. private $dbName = "miq";
  10. private $dbHost = "localhost";
  11.  
  12. private $con = null;
  13.  
  14. //This method must be static, and must return an instance of the object if the object
  15. //does not already exist.
  16. public static function getInstance() {
  17. if (!self::$instance instanceof self) {
  18. self::$instance = new self;
  19. }
  20. return self::$instance;
  21. }
  22.  
  23. // The clone and wakeup methods prevents external instantiation of copies of the Singleton class,
  24. // thus eliminating the possibility of duplicate objects.
  25. public function __clone() {
  26. trigger_error('Clone is not allowed.', E_USER_ERROR);
  27. }
  28. public function __wakeup() {
  29. trigger_error('Deserializing is not allowed.', E_USER_ERROR);
  30. }
  31.  
  32. // private constructor
  33. private function __construct() {
  34. $this->con = mysql_connect($this->dbHost, $this->user, $this->pass)
  35. or die ("Could not connect to db: " . mysql_error());
  36. //SET NAMES sets client, results, and connection character sets
  37. mysql_query("SET NAMES 'utf8'");
  38. mysql_select_db($this->dbName, $this->con)
  39. or die ("Could not select db: " . mysql_error());
  40. }
  41.  
  42. public function get_user_id_by_name ($name) {
  43. $name = mysql_real_escape_string($name);
  44. $result = mysql_query("SELECT id FROM users WHERE name = '"
  45. . $name . "'");
  46. if (mysql_num_rows($result) > 0)
  47. return mysql_result($result, 0);
  48. else
  49. return null;
  50. }
  51.  
  52. public function get_customers_by_user_id($id) {
  53. return mysql_query("SELECT * FROM customers WHERE user_id=" . $id);
  54. }
  55.  
  56. public function get_customer_list_by_user_id($id) {
  57. return mysql_query("SELECT last_name FROM customers WHERE user_id=" . $id);
  58. }
  59.  
  60. public function create_user ($name, $password){
  61. $name = mysql_real_escape_string($name);
  62. $password = mysql_real_escape_string($password);
  63. mysql_query("INSERT INTO users (name, password) VALUES ('" . $name
  64. . "', '" . $password . "')");
  65. }
  66.  
  67. public function verify_user_credentials ($name, $password){
  68. return mysql_num_rows(mysql_query("SELECT * FROM users WHERE name = '"
  69. . $name . "' AND password = '" . $password . "'"));
  70. }
  71.  
  72. public function get_customer_by_customer_id ($customerID) {
  73. return mysql_query("SELECT * FROM customers WHERE id = " . $customerID);
  74. }
  75.  
  76. public function get_window_deduction_by_window_id ($windowsID) {
  77. return mysql_query("SELECT deduction FROM windows WHERE id = " . $windowsID);
  78. }
  79.  
  80. public function insert_customer($user_id, $last_name, $first_name, $address_one, $address_two, $city, $state, $zip_code, $email_address, $phone_one, $phone_two){
  81. return mysql_query("INSERT INTO customers (user_id, last_name, first_name, address_one, address_two, city, state, zip_code, email_address, phone_one, phone_two)" .
  82. "VALUES ('" . $user_id."', '" . $last_name ."', '" . $first_name ."', '" . $address_one ."', '" . $address_two. "', '" . $city. "', '" . $state. "', '" . $zip_code . "', '" . $email_address. "', '" . $phone_one. "', '" . $phone_two. "')");
  83. }
  84.  
  85. public function update_customer($customerID, $last_name, $first_name,$address_one,$address_two,$city,$state,$zip_code,$email_address,$phone_one,$phone_two){
  86. return mysql_query("UPDATE customers SET $last_name = '" . $last_name . "', $first_name = '" . $first_name . "', $address_one = '" . $address_one . "', $address_two= '" . $address_two. "', $city = '" . $city. "', $state = '" . $state. "', $zip_code= '" . $zip_code. "', $email_address = '" . $email_address. "', $phone_one = '" . $phone_two. " WHERE customerid =" . $customerID);
  87. }
  88.  
  89. public function delete_customer ($customerID){
  90. return mysql_query("DELETE FROM customers WHERE id = ".$customerID);
  91. }
  92.  
  93. public function insert_quote($user_id, $customer_id, $total, $commission){
  94. return mysql_query("INSERT INTO quotes (user_id, customer_id, total, commission)" .
  95. "VALUES (" . $user_id.", '" . $customer_id ."', " . $total ."', " . $commission ."', " . $address_two. "', ");
  96. }
  97.  
  98. public function format_date_for_sql($date){
  99. if ($date == "")
  100. return "NULL";
  101. else {
  102. $dateParts = date_parse($date);
  103. return $dateParts["year"]*10000 + $dateParts["month"]*100 + $dateParts["day"];
  104. }
  105. }
  106. }
  107. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement