0

I have a simple query that selects a PIN from a list of numbers, and then assigns that PIN to a user and inserts it into another table:

$sth = $this->db->query("SELECT available_pins FROM pin_list ORDER BY RAND() LIMIT 0,1 ;");
$pinarray = $sth->fetch();
$this->user_pin = $pinarray;

$sth = $this->db->prepare("INSERT INTO users (user_email, user_pin) VALUES(:user_email,  :user_pin) ;");
$sth->execute(array(':user_email' => $this->user_email, ':user_pin' => $this->user_pin));

However, this creates a Catchable fatal error: Object of class stdClass could not be converted to string, any ideas?

Additional info

$sth->execute(array gives the error, available_pins uses mediumint(6). It is a list of random 6 digit numbers.

4
  • Which line gives you the error? Commented Oct 11, 2013 at 18:43
  • $sth->execute(array gives the error. Commented Oct 11, 2013 at 18:44
  • You might want to add a VALUES clause to that INSERT statement. You're just assuming it's worked - you need to check return values and handle things appropriately when they fail. Commented Oct 11, 2013 at 18:45
  • I had a typo; VALUES are in the INSERT statement as above Commented Oct 11, 2013 at 18:46

1 Answer 1

1

Looks like $pinarray is an instance of StdClass. You probably intend to grab the available_pins field, eh?

$pinarray = $sth->fetch();
$this->user_pin = $pinarray->available_pins;
Sign up to request clarification or add additional context in comments.

2 Comments

I think it's two fold, he's trying to pass in an array of values to the execute statement, but instead they should be bound using bind_param() no?
@Ohgodwhy I'd just be guessing with respect to the DB abstraction layer that is being used in $sth. Some use the syntax shown in the question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.