开发者

MySQL SELECT with PK as key of result set

开发者 https://www.devze.com 2023-03-29 13:29 出处:网络
Is it possible to use SELECT state开发者_StackOverflowment in MySQL such that key of the result-set rows is the actual PK of table rows?

Is it possible to use SELECT state开发者_StackOverflowment in MySQL such that key of the result-set rows is the actual PK of table rows?

result set = PHP associative arrays

PK is auto-increment


There is no native function to do that.

But you can quite easily iterate that resultset and set keys by your own.

$data = array();
while ($row = mysql_fetch_assoc($result)) {
    $data[ $row['id'] ] = $row;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号