Home  >  Article  >  php教程  >  pdo连接数据库与查询与保存数据到mysql

pdo连接数据库与查询与保存数据到mysql

WBOY
WBOYOriginal
2016-05-24 18:31:061518browse

这是一款利用php+pdo+mysql的操作实例,就是利用pdo连接数据库与查询与保存数据到mysql中呢,pdo数据保存,代码如下:

<?php  
	$pdo = new pdo("mysql:host=localhost;dbname=db_demo","root","");  
	if($pdo -> exec("insert into db_demo(name,content) values(&#39;title&#39;,&#39;content&#39;)")){  
	echo "插入成功!";  
	echo $pdo -> lastinsertid();  
	}  
	 

查询数据库,代码如下:

<?php  
	$pdo = new pdo("mysql:host=localhost;dbname=db_demo","root","");  
	$rs = $pdo -> query("select * from test");  
	while($row = $rs -> fetch()){  
	print_r($row); //开源代码phprm.com 
	}  
	

本文链接:

收藏随意^^请保留教程地址.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn