Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class miqDB {
- // single instance of self shared among all instances
- private static $instance = null;
- // db connection config vars
- private $user = "miq_sys";
- private $pass = "monkey";
- private $dbName = "miq";
- private $dbHost = "localhost";
- private $con = null;
- //This method must be static, and must return an instance of the object if the object
- //does not already exist.
- public static function getInstance() {
- if (!self::$instance instanceof self) {
- self::$instance = new self;
- }
- return self::$instance;
- }
- // The clone and wakeup methods prevents external instantiation of copies of the Singleton class,
- // thus eliminating the possibility of duplicate objects.
- public function __clone() {
- trigger_error('Clone is not allowed.', E_USER_ERROR);
- }
- public function __wakeup() {
- trigger_error('Deserializing is not allowed.', E_USER_ERROR);
- }
- // private constructor
- private function __construct() {
- $this->con = mysql_connect($this->dbHost, $this->user, $this->pass)
- or die ("Could not connect to db: " . mysql_error());
- //SET NAMES sets client, results, and connection character sets
- mysql_query("SET NAMES 'utf8'");
- mysql_select_db($this->dbName, $this->con)
- or die ("Could not select db: " . mysql_error());
- }
- public function get_user_id_by_name ($name) {
- $name = mysql_real_escape_string($name);
- $result = mysql_query("SELECT id FROM users WHERE name = '"
- . $name . "'");
- if (mysql_num_rows($result) > 0)
- return mysql_result($result, 0);
- else
- return null;
- }
- public function get_customers_by_user_id($id) {
- return mysql_query("SELECT * FROM customers WHERE user_id=" . $id);
- }
- public function get_customer_list_by_user_id($id) {
- return mysql_query("SELECT last_name FROM customers WHERE user_id=" . $id);
- }
- public function create_user ($name, $password){
- $name = mysql_real_escape_string($name);
- $password = mysql_real_escape_string($password);
- mysql_query("INSERT INTO users (name, password) VALUES ('" . $name
- . "', '" . $password . "')");
- }
- public function verify_user_credentials ($name, $password){
- return mysql_num_rows(mysql_query("SELECT * FROM users WHERE name = '"
- . $name . "' AND password = '" . $password . "'"));
- }
- public function get_customer_by_customer_id ($customerID) {
- return mysql_query("SELECT * FROM customers WHERE id = " . $customerID);
- }
- public function get_window_deduction_by_window_id ($windowsID) {
- return mysql_query("SELECT deduction FROM windows WHERE id = " . $windowsID);
- }
- public function insert_customer($user_id, $last_name, $first_name, $address_one, $address_two, $city, $state, $zip_code, $email_address, $phone_one, $phone_two){
- 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)" .
- "VALUES ('" . $user_id."', '" . $last_name ."', '" . $first_name ."', '" . $address_one ."', '" . $address_two. "', '" . $city. "', '" . $state. "', '" . $zip_code . "', '" . $email_address. "', '" . $phone_one. "', '" . $phone_two. "')");
- }
- public function update_customer($customerID, $last_name, $first_name,$address_one,$address_two,$city,$state,$zip_code,$email_address,$phone_one,$phone_two){
- 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);
- }
- public function delete_customer ($customerID){
- return mysql_query("DELETE FROM customers WHERE id = ".$customerID);
- }
- public function insert_quote($user_id, $customer_id, $total, $commission){
- return mysql_query("INSERT INTO quotes (user_id, customer_id, total, commission)" .
- "VALUES (" . $user_id.", '" . $customer_id ."', " . $total ."', " . $commission ."', " . $address_two. "', ");
- }
- public function format_date_for_sql($date){
- if ($date == "")
- return "NULL";
- else {
- $dateParts = date_parse($date);
- return $dateParts["year"]*10000 + $dateParts["month"]*100 + $dateParts["day"];
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement