function getTodayAllSupplyToTble() { $dbmain = new DBmain(); $res = $dbmain->selectAllData("today_supply"); foreach ($res as $r) { echo $r['f_name']; } }
function approxTeaRatesOfLast6Months() { $dbmain = new DBmain(); $formateddate = date("Y-m-d"); $resarr = array(); $curyear = substr($formateddate, 0, 4); $curmonth = substr($formateddate, 5, 7); $curmonth = $curmonth * 1 + 1; $lstrunningmonth = substr($formateddate, 5, 7); for ($i = 1; $i < 7; $i++) { $lstrunningmonth = $curmonth - $i; $m = $curmonth - $i; if ($lstrunningmonth == "0") { $curyear = $curyear - 1; $m = 12 + ($curmonth - $i); } if ($lstrunningmonth < 0) { $m = 12 + ($curmonth - $i); } if (strlen($m) == 1) { $m = "0" . $m; } $startday = $curyear . "-" . $m . "-01"; $enddate = $curyear . "-" . $m . "-31"; $condition = " WHERE date BETWEEN '" . $startday . "' AND '" . $enddate . "'"; $res = $dbmain->selectData("settings", array("approxi_tea_rate"), $condition); $total = 0; if (count($res) > 0) { foreach ($res as $r) { $total = $total + $r['approxi_tea_rate']; } $resarr[$i - 1] = $total; } else { $resarr[$i - 1] = 0; } } return $resarr; }
function teaRateofMonth($formateddate) { $dbmain = new DBmain(); $startday = substr($formateddate, 0, 7) . "-01"; $enddate = substr($formateddate, 0, 7) . "-31"; $condition = " WHERE date BETWEEN '" . $startday . "' AND '" . $enddate . "'"; $res = $dbmain->selectData("settings", array("approxi_tea_rate", "fixed_tea_rate"), $condition); if (count($res) == 1) { foreach ($res as $r) { $approx = $r['approxi_tea_rate']; $real = $r['fixed_tea_rate']; if ($real != NULL || $real != 0) { return $real; } else { return $approx; } } } elseif (count($res) > 1) { $approx = ""; $real = ""; foreach ($res as $r) { $approx = $r['approxi_tea_rate']; $real = $r['fixed_tea_rate']; } return $real; } else { return 0; } }
public function insert($tablename, $datafields = array(), $tablefields = array()) { //insert data $dbconfig = new DBconfig(); $host = $dbconfig->host(); $user = $dbconfig->username(); $pwd = $dbconfig->pwd(); $db = $dbconfig->db(); $datafld = DBmain::arraytostr2($datafields); //convert array to a single string separate with "," $tablefld = DBmain::arraytostr($tablefields); try { $conn = new PDO("mysql:host={$host};dbname={$db}", $user, $pwd); // set the PDO error mode to exception $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $sql = "INSERT INTO " . $tablename . " (" . $tablefld . ") VALUES (" . $datafld . ")"; // use exec() because no results are returned $conn->exec($sql); return true; } catch (PDOException $e) { echo $sql . "<br>" . $e->getMessage(); return false; } $conn = null; }
public function selectDataCommen($query) { //select Data $selectrowsstr = DBmain::arraytostr($selectrows); try { $stmt = $this->conn->prepare($query); $stmt->execute(); // set the resulting array to associative //$result = $stmt->setFetchMode(PDO::FETCH_ASSOC); $arr = array(); //create outer array if ($stmt->rowCount() > 0) { $count = 0; while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { $arr[$count] = $row; //inner associative array ($row) is emberd to outer array $count++; } } return $arr; } catch (PDOException $e) { echo "Error: " . $e->getMessage(); } $conn = null; }
function getSuppliersToTble() { $dbmain = new DBmain(); $res = $dbmain->selectAllData("suppliers", "LIMIT 0,25"); foreach ($res as $r) { echo $r['f_name']; } }