Guest User

Untitled

a guest
Feb 1st, 2019
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. <?php
  2. class Connection
  3. {
  4. private $conn;
  5. private $host;
  6. private $username;
  7. private $password;
  8. private $database;
  9. private $port;
  10. private $debug;
  11. private $attributes;
  12. function Connection($params=array())
  13. {
  14. //error_reporting(0);
  15. $this->conn = false;
  16. $this->host ='localhost';
  17. $this->username ='root';
  18. $this->password ='';
  19. $this->database ='easyway';
  20. $this->port = '';
  21. $this->debug = true;
  22. $attributes=array(
  23. PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'
  24. );
  25. $this->connect();
  26. session_start();
  27. }
  28. function __destruct()
  29. {
  30. //$this->Close();
  31. }
  32. function connect() //connection
  33. {
  34. if (!$this->conn) {
  35. try {
  36. $this->conn = new PDO('mysql:host='.$this->host.';dbname='.$this->database.'', $this->username, $this->password, $this->attributes);
  37. }
  38. catch (Exception $e) {
  39. die('Error : ' . $e->getMessage());
  40. echo"Connect Error";
  41. }
  42.  
  43. if (!$this->conn) {
  44. $this->status_fatal = true;
  45. echo 'Connection failed';
  46. die();
  47. }
  48. else {
  49. $this->status_fatal = false;
  50. }
  51. }
  52.  
  53. return $this->conn;
  54. }
  55. function Close()
  56. {
  57. if ($this->conn) {
  58. $this->conn = null;
  59. }
  60. }
  61. }
  62.  
  63. class Insertion extends Connection
  64. {
  65. function Insertion($tablename,$data,$other)
  66. {
  67. $conn=parent::connect();
  68. $fields = array_keys($data);
  69. echo $sql = "INSERT INTO ".$tablename."
  70. (`".implode('`,`', $fields)."`)
  71. VALUES('".implode("','", $data)."');";
  72. $prepared=$conn->prepare($sql);
  73. $prepared->execute($data);
  74. print_r($prepared->errorInfo());
  75. //print_r($prepared->errorCode());
  76. }
  77. function page_redirect($other)
  78. {
  79. extract($other);
  80. print_r($other);
  81. echo $page;
  82. header("location:$page.php?$message");
  83. }
  84. }
  85. ?>
  86. =============================Invoking Page===============================
  87.  
  88. Array ( [0] => 3D000 [1] => 1046 [2] => No database selected )
Add Comment
Please, Sign In to add comment