Guest User

Untitled

a guest
Aug 21st, 2018
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. php pdo save query data
  2. : Call to a member function rowCount() on a non-object in C:wampwwwprjyclassesuser.php on line 34
  3.  
  4. $this->sth = $this->dbh->prepare("SELECT id, userlevel FROM users WHERE username = ? AND password = ?");
  5. $this->sth->bindParam(1, $username);
  6. $this->sth->bindParam(2, $password);
  7. $this->data = $this->sth->execute();
  8.  
  9. if ($this->data->rowCount() > 0)
  10.  
  11. count($this->data)
  12.  
  13. $stmt1 = $this->dbh->prepare( /* first select statement */ );
  14. $stmt1->bindParam(1, $username);
  15. $stmt1->bindParam(2, $password);
  16.  
  17. $stmt2 = $this->dbh->prepare( /* second select statement */ );
  18. $stmt2->bindParam(1, $username);
  19. $stmt2->bindParam(2, $password);
  20.  
  21. if( $stmt1->execute() && $stmt2->execute() )
  22. {
  23. if( $stmt1->rowCount() > 0 )
  24. {
  25. $result = $stmt1->fetchAll();
  26. }
  27. else if( $stmt2->rowCount() > 0 )
  28. {
  29. $result = $stmt2->fetchAll();
  30. }
  31. }
  32.  
  33. $db = new PDO(
  34. 'dsn connection string',
  35. 'username',
  36. 'password',
  37. array( PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true )
  38. );
  39.  
  40. $this->sth = $this->dbh->prepare("SELECT id, userlevel FROM users WHERE username = ? AND password = ?");
  41. $this->sth->bindParam(1, $username);
  42. $this->sth->bindParam(2, $password);
  43. if($this->data = $this->sth->execute()) {
  44. if ($this->data->rowCount() > 0) {
  45. // do something here ..
  46. }
  47. }
  48.  
  49. if (!$this->data = $this->sth->execute()) { echo "ERROR!"; print_r($this->sth->errorInfo()); die(); }
Add Comment
Please, Sign In to add comment