Hi,
I have the following model:
class Robot extends \Phalcon\Mvc\Model{
public static function getByName($name = '') {
$sql = "CALL sp_getByName('$name');";
$robot = new Robot();
return new Resultset(null, $robot, $robot->getReadConnection()->query($sql));
}
}
and called in the controller:
$name = "Johnny No. 5";
$robot = Robot::getByName($name)->toArray();
var_dump($robot);
This function calls a stored procedure from mysql. Using it this way does it automatically prevent sql injections or do I need to bind the values? (if so would you be able to provide an example).
Secondly the results are being returned as follows:
array(1) {
[0]=>
array(2) {
["name"]=>
string(12) "Johnny No. 5"
["age"]=>
string(1) "6"
}
}
Is there an easy way for them to be returned as:
array(2) {
["name"]=>
string(12) "Johnny No. 5"
["age"]=>
string(1) "6"
}
This specific stored procdure only return 1 row of results, so I don't need the results to be retuned as an array of an array it would just makes things cleaner to work with.
Thanks