<?php 
/****************************************************************/
/*          e-mo.pl © 2017                                      */
/*          http://www.e-mo.com.pl                              */
/*          e-mail: info@e-mo.pl                                */
/*          produkt: Action2osCommerce                          */
/*          wersja: 1.9.7                                       */
/*          webserwis: oscGold                                  */
/*          sciezka: https://www.e-mo.com.pl/plikit,1918,533545b244d7d.php*/
/*          data: 2017-09-25                                    */
/*          godz: 10:45:35                                      */
/****************************************************************/

class products_to_categories { 
	public $Conn = 0;
	public $errMsg = '';
	public $errNo= 0;
	public $products_id=0;
	public $categories_id=0;

	public function Dodaj(){
		$zwrot=true;
		$query="Insert products_to_categories (products_id, categories_id) VALUES (:products_id, :categories_id) ";
		$sth = $this->Conn->prepare($query);

		$sth->bindParam(':products_id', $this->products_id, PDO::PARAM_INT);
		$sth->bindParam(':categories_id', $this->categories_id, PDO::PARAM_INT);

		$sth->execute();

		if($sth->errorCode() != 0){
			$zwrot=false;
			$this->errMsg = $sth->errorInfo();
			$this->errNo = $sth->errorCode();
		}

		 return $zwrot;
	 } 
	public function Zmien(){
		$zwrot=true;
		$query="Update products_to_categories SET products_id=:products_id, categories_id=:categories_id";
		$sth = $this->Conn->prepare($query);

		$sth->bindParam(':products_id', $this->products_id, PDO::PARAM_INT);
		$sth->bindParam(':categories_id', $this->categories_id, PDO::PARAM_INT);

		$sth->execute();

		if($sth->errorCode() != 0){
			$zwrot=false;
			$this->errMsg = $sth->errorInfo();
			$this->errNo = $sth->errorCode();
		}

		 return $zwrot;
	 } 
	public function Usun(){
		$zwrot=true;
		$query="Delete from products_to_categories Where products_id=:products_id";

		$sth = $this->Conn->prepare($query);
		$sth->bindParam(':products_id', $this->products_id, PDO::PARAM_INT);
		$sth->execute();

		if($sth->errorCode() != 0){
			$zwrot=false;
			$this->errMsg = $sth->errorInfo();
			$this->errNo = $sth->errorCode();
		}

		 return $zwrot;
	 } 
	public function Lista(){
		$query='Select * from products_to_categories';
		$sth = $this->Conn->prepare($query);
		$sth->execute();
		$tablica = array();
		$x=0;

		while ($row = $sth->fetch(PDO::FETCH_ASSOC, PDO::FETCH_ORI_NEXT))
		{
			foreach ($row as $k => $v)
			{
				$tablica[$x][$k]=trim($v);
			}
			$x++;
		}

		return $tablica;
	}

}
?>
