object of class could not be converted to string code example

Example 1: object of class pdostatement could not be converted to string

In the comments, you show the following:

$query = $db->query('SELECT MAX( Bestelnummer ) FROM Bestellingsdetail');
$query->execute();
$max = $query;
$max++;
This is not how you get the result from a query. You are setting $max to a PDOStatement object. You need to fetch() the result in order to use it.

// I've added "AS maxval" to make it easier to get the row
$query = $db->query('SELECT MAX(Bestelnummer) AS maxval FROM Bestellingsdetail');
$max_row = $query->fetch(PDO::FETCH_ASSOC);

$max = $max_row['maxval'];
$max++;
Docs: http://www.php.net/pdo.query

P.S. $query->execute(); is only needed for prepared statements. query() will execute the query immediately.

Example 2: object of class stdclass could not be converted to string

Most likely, the userdata() function is returning an object, not a string. Look into the documentation (or var_dump the return value) to find out which value you need to use.

Tags:

Misc Example