Advertisement
Guest User

php

a guest
Jul 14th, 2016
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. <?php
  2.  
  3. class Check{
  4. private $_hostname;
  5. private $_username;
  6. private $_password;
  7. private $_dbname;
  8. private $_conn;
  9.  
  10. public function __construct($hostname, $username, $password, $dbname){
  11. $this -> _hostname=$hostname;
  12. $this -> _username=$username;
  13. $this -> _password=$password;
  14. $this -> _dbname=$dbname;
  15. }
  16.  
  17. public function connect(){
  18. $this->_conn = new mysqli ($this->_hostname, $this->_username, $this->_password, $this->_dbname);
  19. if ($this->_conn->connect_error) {
  20. //die ( "Connection failed: " . $conn->connect_error );
  21. } else {
  22. //echo "Connected";
  23. }
  24. $this->_conn->set_charset("utf8");
  25. echo "Connection. </br>";
  26. return $this->_conn;
  27. }
  28.  
  29. public function get_ean(){
  30. $xml=simplexml_load_file("orders.xml") or die("Error: Cannot create object");
  31. echo "EAN: " .$xml->{"Order-Lines"}->Line->{"Line-Item"}->EAN;
  32. echo "<br/>BuyerItemCode: ".$xml->{"Order-Lines"}->Line->{"Line-Item"}->BuyerItemCode ."<br/>";
  33. $EAN=$xml->{"Order-Lines"}->Line->{"Line-Item"}->EAN;
  34. return $EAN;
  35. }
  36.  
  37. public function check($EAN){
  38. $returned = array();
  39. $data = array();
  40. $query = "SELECT id_string from products WHERE id_string like '$EAN%'";
  41. $query1 = "SELECT id_string from eans e left join products p on e.id_product = p.id WHERE id_ean_string like '$EAN%'";
  42.  
  43. if($result = $this->_conn -> query( $query )) {
  44. $counter = 0;
  45. while($obj = $result->fetch_object()){
  46. $data[$counter]["id_string"] = $obj->id_string;
  47. $counter++;
  48. $code = $obj -> id_string;
  49. }
  50. $returned["data"] = $data;
  51. }
  52.  
  53. if ($result = $this->_conn->query( $query1 )) {
  54. $counter = 0;
  55. while($obj = $result->fetch_object()){
  56. $data[$counter]["ean"] = $obj->id_string;
  57. $counter++;
  58. $code = $obj -> id_string;
  59. }
  60. $returned["data"] = $data;
  61. }
  62. echo "EAN from base: ";
  63. print($code);
  64. return $code;
  65. }
  66.  
  67. public function close(){
  68. $this->_conn->close();
  69. }
  70.  
  71. }
  72.  
  73. $hostname = 'localhost';
  74. $username = 'Admin';
  75. $password = 'Admin';
  76. $dbname = 'warehouse';
  77. $BuyerItemCode = "61908";
  78.  
  79. $sth = new Check($hostname, $username, $password, $dbname);
  80. $sth->connect();
  81. $ean=$sth->get_ean();
  82. $sth->check($ean);
  83. $sth->close();
  84.  
  85. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement