I am almost sure that the error is here:

PHP Code:

$pedido_query 
$db->Execute("select orders_id from " TABLE_ORDERS " order by orders_id desc limit 0,1");
$res_pedido $db->Execute($pedido_query); 
Please help!!