Advertisement
Guest User

Untitled

a guest
Oct 21st, 2017
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.28 KB | None | 0 0
  1. Logs:
  2. [Sat Oct 21 14:10:42 2017] [error] [client 173.x.x.x] PHP Warning: mysqli_stmt::bind_param(): Number of elements in type definition string doesn't match number of bind variables in /var/www/classes/Database.php on line 44
  3. [Sat Oct 21 14:10:42 2017] [error] [client 173.x.x.x] PHP Fatal error: Uncaught exception 'Exception' with message 'Binding parameters failed: ' in /var/www/classes/Database.php:46\nStack trace:\n#0 /var/www/classes/paypal-listener.php(36): Database->query('INSERT INTO pay...', Array)\n#1 {main}\n thrown in /var/www/classes/Database.php on line 46
  4.  
  5. Database.php file:
  6. <?php
  7. class Database
  8. {
  9. private $db;
  10.  
  11. private $host;
  12. private $user;
  13. private $password;
  14. private $database;
  15.  
  16. private $types = [
  17. 'string' => 's',
  18. 'integer' => 'i'
  19. ];
  20.  
  21. public function __construct($host, $user, $password, $database) {
  22. $this->host = $host;
  23. $this->user = $user;
  24. $this->password = $password;
  25. $this->database = $database;
  26.  
  27. $this->db = new MySQLi($host, $user, $password, $database);
  28.  
  29. if ($this->db->connect_errno)
  30. throw new Exception('Failed to connect to the MySQL database: ' . $this->db->connect_error);
  31. }
  32.  
  33. public function query($query, $params = []) {
  34. $statement = $this->db->prepare($query);
  35. if (!$statement)
  36. throw new Exception('Preparing statement faile: ' . $this->db->error);
  37.  
  38. $typeStr = '';
  39. foreach ($params as $param) {
  40. $type = gettype($param);
  41.  
  42. if (!array_key_exists($type, $this->types))
  43. throw new Exception('Variable has no known type: ' . $param);
  44.  
  45. $typeStr .= $this->types[$type];
  46. }
  47.  
  48. if (count($params) > 0) {
  49. $bind = $statement->bind_param($typeStr, $params);
  50. if (!$bind)
  51. throw new Exception('Binding parameters failed: ' . $statement->error);
  52. }
  53.  
  54. $exec = $statement->execute();
  55. if (!$exec)
  56. throw new Exception('Binding parameters failed: ' . $statement->error);
  57.  
  58. $result = $statement->get_result();
  59.  
  60. $statement->close();
  61.  
  62. return $result;
  63. }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement