所以我有几个简单的MySQL程序:
A:
CREATE DEFINER=`root`@`localhost` PROCEDURE `selectUsername`(_id INT(11))
DETERMINISTIC
COMMENT 'Select username given id'
BEGIN
SELECT username FROM registered WHERE id=_id;
END
B:
CREATE DEFINER=`root`@`localhost` PROCEDURE `selectCountryIdOfUser`(_id INT(11))
DETERMINISTIC
COMMENT 'Select country id given registered user id'
BEGIN
SELECT COUNTRY_id FROM registered WHERE id=_id;
END
现在,出于某种原因,在通过PHP PDO声明之后:
$stmt=$dbconnect->prepare("CALL selectUsername(:userid);");
$stmt->bindValue(':userid',$userid,PDO::PARAM_INT);
$stmt->execute();
$result=$stmt->fetchAll(PDO::FETCH_ASSOC);
使用print_r($result)
:
A:
Array ( [username] => 'Test' )
B:
Array ( [0] => Array ( [COUNTRY_id] => 235 ) )
我想知道的是,为什么B在嵌套数组中返回结果?所以现在,当我想引用该值时,我必须使用0数组:$result[0]['COUNTRY_id']