Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Check{
- private $_hostname;
- private $_username;
- private $_password;
- private $_dbname;
- private $_conn;
- public function __construct($hostname, $username, $password, $dbname){
- $this -> _hostname=$hostname;
- $this -> _username=$username;
- $this -> _password=$password;
- $this -> _dbname=$dbname;
- }
- public function connect(){
- $this->_conn = new mysqli ($this->_hostname, $this->_username, $this->_password, $this->_dbname);
- if ($this->_conn->connect_error) {
- //die ( "Connection failed: " . $conn->connect_error );
- } else {
- //echo "Connected";
- }
- $this->_conn->set_charset("utf8");
- echo "Connection. </br>";
- return $this->_conn;
- }
- public function get_ean(){
- $xml=simplexml_load_file("orders.xml") or die("Error: Cannot create object");
- echo "EAN: " .$xml->{"Order-Lines"}->Line->{"Line-Item"}->EAN;
- echo "<br/>BuyerItemCode: ".$xml->{"Order-Lines"}->Line->{"Line-Item"}->BuyerItemCode ."<br/>";
- $EAN=$xml->{"Order-Lines"}->Line->{"Line-Item"}->EAN;
- return $EAN;
- }
- public function check($EAN){
- $returned = array();
- $data = array();
- $query = "SELECT id_string from products WHERE id_string like '$EAN%'";
- $query1 = "SELECT id_string from eans e left join products p on e.id_product = p.id WHERE id_ean_string like '$EAN%'";
- if($result = $this->_conn -> query( $query )) {
- $counter = 0;
- while($obj = $result->fetch_object()){
- $data[$counter]["id_string"] = $obj->id_string;
- $counter++;
- $code = $obj -> id_string;
- }
- $returned["data"] = $data;
- }
- if ($result = $this->_conn->query( $query1 )) {
- $counter = 0;
- while($obj = $result->fetch_object()){
- $data[$counter]["ean"] = $obj->id_string;
- $counter++;
- $code = $obj -> id_string;
- }
- $returned["data"] = $data;
- }
- echo "EAN from base: ";
- print($code);
- return $code;
- }
- public function close(){
- $this->_conn->close();
- }
- }
- $hostname = 'localhost';
- $username = 'Admin';
- $password = 'Admin';
- $dbname = 'warehouse';
- $BuyerItemCode = "61908";
- $sth = new Check($hostname, $username, $password, $dbname);
- $sth->connect();
- $ean=$sth->get_ean();
- $sth->check($ean);
- $sth->close();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement