mysql的结果集返回php数组

mysql的结果集返回php数组,第1张

$pdo = new PDO('mysql:host=localhostdbname=','root','')

$data = $pdo->query('SELECT * FROM `user`')

foreach($data as $v){

echo $v['id']

}

正常情况下你还应该处理异常

try{

$pdo = new PDO('mysql:host=localhostdbname=','root','')

$data = $pdo->query('SELECT * FROM `user`')

foreach($data as $v){

print_r($v)

}

}catch(PDOException $e){

}

数组序列化存储,例如

$stooges

=

array('Moe','Larry','Curly')

$new

=

serialize($stooges)

print_r($new)echo

"<br

/>"

print_r(unserialize($new))

结果:a:3:{i:0s:3:"Moe"i:1s:5:"Larry"i:2s:5:"Curly"}

Array

(

[0]

=>

Moe

[1]

=>

Larry

[2]

=>

Curly

)

把$new写进数据库就行啦


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/7320416.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-04
下一篇 2023-04-04

发表评论

登录后才能评论

评论列表(0条)

保存