Possible Duplicate:
Output (echo/print) everything from a PHP Array
I have done a query from a database and the result is stored in a variable which is believe is an array. The output is only one row and column so i use:
echo result[0];
to output the result.
However i get an error saying:
Notice: Array to string conversion in "C:/apache/htdocs...."
array
I tried to dump the variable using
var_dump result[0];
I then get this
array(1) { [0]=> array(1) { ["var_datain"]=> string(4) "hai!" } }
So…. how do i get it to echo out the value hai! from that array?
In case it matters, here is my query
$db = new PDO(DSN, DBUSER, DBPASS);
$stmt = $db->prepare("CALL test(?)");
$parameter = 'hai!';
$stmt->bindValue(1, $parameter, PDO::PARAM_STR);
$rs = $stmt->execute();
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
var_dump($result);
It’s a multidimensional array.
It depends of the way you did your query (show us more code to explain you better) but it looks that in your case each line returned by your query is another array containing the columns that you selected. Even if you select only one col and only one row, it’s still returned as a multidimensional array.
Got it?