I currently have a database call which works in one area, but not another.
My database class is labeled $database and has the $db
PDO object passed to the database constructor.
This all works fine.
This code call works
$user_info = $database->get_user($user);
This function is called
public function get_user($user){
$user = $this->db->quote($user);
$query = "SELECT * FROM login where username = $user";
$user = $this->db->query($query);
$user_info = $user->fetch();
return $user_info;}
This returns the user info as expected
Another call is
$user = $database->confirm($confirm);
$user_info = $database->get_user($user);
The confirm function looks like this
public function confirm($confirm){
$confirm = $this->db->quote($confirm);
$query = "SELECT * FROM temp_data WHERE hash = $confirm;";
$count = $this->db->query($query);
$info = $count->fetch();
$user = $info['username'];
$user = $this->db->quote($user);
$query = "DELETE FROM temp_data WHERE username = $user;";
$this->db->exec($query);
$query = "UPDATE login SET confirm = '1' WHERE username = $user;";
$this->db->exec($query);
return $info['username'];}
This call works perfectly.
It returns the username in an unquoted format which the get_user
accepts
However the get_user
fails
I have done troubleshooting and found the issue is that the following line in get_user
is not returning any PDO object, or any data at all
$user = $this->db->query($query);
This is the interesting part. I did a try catch and the PDO is throwing no PDO exception and it is not even throwing a general exception. There are no errors in the error log. It just appears not to be working. I have went through step by step using Print_r
, get_class
, and echo
followed by a die;
to output my results and it all works up until I do the second database call. The fetch is returning an error, but that is only due to the fact the exec is not running at all it seems
I did try using unset()
on everything but my main DB connection that is created and passed into my database object when it is created
Here is what is happening when the script is run
- The user clicks on a link with a random hash
- The system gets the hash from the GET and then uses that too pull the user name from the temp database.
- It then modifies the user as confirmed, deletes the temp entry and then returns the user name
- from here it then calls the
get_user
. In this case it just returns the user information to set up the twilio sub account. This is where the system is failing - After that what happens (And this it does try to do from my testing because i get an error here) is that it accesses the twilio API, gets a sub acount AUTH and SID token and writes it to the users file
- Then the new user is redirected to the signin page
I have tried using close cursor and it has not worked.
If anyone can give me any insight into the issue I am having, or what I am doing wrong I would appreciate it. I am new to using the PDO object so I am sure I have made a stupid mistake somewhere.