MySQL PDO连接与操作

WBOY
Lepaskan: 2016-08-08 09:21:47
asal
1175 orang telah melayarinya
<p>//实例化PDO类 连接数据库  参数是 mysql:host=localhost;dbname=lamp 用户名  密码
$pdo = new PDO('mysql:host=localhost;dbname=lamp', 'root', '');</p><p>//查询语句
</p><p>$sql = "select * from lamp_login";
$stmt = $pdo->query($sql);</p><p>//增 删  改</p><p>$pdo->exec($sql);
</p><p>PDO::FETCH_OBJ相当于mysql_fetch_object</p><pre dir="ltr">object(<em>stdClass</em>)[<em>3</em>]
  <em>public</em> 'id' <span>=></span><small>string</small><span>'1'</span><em>(length=1)
  public</em> 'username' <span>=></span><small>string</small><span>'user1'</span><em>(length=5)
  public</em> 'password' <span>=></span><small>string</small><span>'123'</span><em>(length=3)</em>
Salin selepas log masuk

PDO::FETCH_BOTH相当于mysql_fetch_array

array<em>(size=6)</em>
  'id' <span>=></span><small>string</small><span>'2'</span><em>(length=1)</em>
  0 <span>=></span><small>string</small><span>'2'</span><em>(length=1)</em>
  'username' <span>=></span><small>string</small><span>'user2'</span><em>(length=5)</em>
  1 <span>=></span><small>string</small><span>'user2'</span><em>(length=5)</em>
  'password' <span>=></span><small>string</small><span>'234'</span><em>(length=3)</em>
  2 <span>=></span><small>string</small><span>'234'</span><em>(length=3)</em>
Salin selepas log masuk

PDO::FETCH_NUM相当于mysql_fetch_row

array<em>(size=3)</em>
  0 <span>=></span><small>string</small><span>'3'</span><em>(length=1)</em>
  1 <span>=></span><small>string</small><span>'user3'</span><em>(length=5)</em>
  2 <span>=></span><small>string</small><span>'345'</span><em>(length=3)</em>
Salin selepas log masuk

PDO::FETCH_ASSOC相当于mysql_fetch_assoc

array<em>(size=3)</em>
  'id' <span>=></span><small>string</small><span>'4'</span><em>(length=1)</em>
  'username' <span>=></span><small>string</small><span>'zhouyao'</span><em>(length=7)</em>
  'password' <span>=></span><small>string</small><span>'123456'</span><em>(length=6)</em>
Salin selepas log masuk

版权声明:本文为博主原创文章,未经博主允许不得转载。

以上就介绍了MySQL PDO连接与操作,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

Label berkaitan:
sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan