Advertisement
Guest User

functions/

a guest
May 5th, 2017
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. <?php
  2. //config-db.php
  3. define('DB_SERVER','localhost') ;
  4. define('DB_USER','root');
  5. define('DB_PASS','toor');
  6. define('DB_DATABASE','myweb');
  7.  
  8.  
  9. ?>
  10.  
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17.  
  18.  
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27. <?php
  28. //userAPI.php
  29. include "config-db.php" ;
  30. class userAPI{
  31. public $db;
  32.  
  33. function __contruct(){
  34.  
  35. $this->db=new mysqli(DB_SERVER,DB_USER,DB_PASS,DB_DATABASE);
  36. if ($this->db->connect_error){
  37. die ("error connect database!");
  38. exit;
  39.  
  40. }
  41.  
  42.  
  43. }
  44. function login($username,$password){
  45.  
  46. $select=$this->db->query("select * from users where username='$username' and password='$username'") or die ("c'ant select!!");
  47. if($select->num_rows>0){
  48. return true;}
  49. else{
  50. print "خطأفي الاسم اوكلمة المرور";
  51. return false;
  52. }
  53. }
  54. function update($username,$password,$id){
  55.  
  56. if (!isset($id)){
  57. print "bad request";
  58. }
  59. $id=intval($id);
  60. if ($id='0'){
  61. print "bad request";
  62. }
  63. else{
  64.  
  65. $select=$this->db->query("UPDATE users set username='$username' and password='$username' where id='$id'") or die ("c'ant select!!");
  66.  
  67. }
  68.  
  69.  
  70.  
  71. }
  72.  
  73. function select(){
  74.  
  75. $select=$this->db->query("select * from users where id='$id'") or die ("c'ant select!!");
  76. $fetch=$select->fetch_array('MYSQLI_ASSOC');
  77. $username_db=$fetch['username'];
  78. $password_db=$fetch['password'];
  79. $id_db=$fetch['id'];
  80. $lvl_db=$fetch['lvl'];
  81.  
  82. }
  83.  
  84.  
  85.  
  86. }
  87.  
  88.  
  89.  
  90. $dz=new userAPI();
  91. $dz->login('dz','dz');
  92.  
  93.  
  94. ?>
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112. :========problleme=========:
  113.  
  114. Fatal error: Call to a member function query() on a non-object in /var/www/html/site/admin/functions/userAPI.php on line 19
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement