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

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

WBOY
Release: 2016-05-24 18:31:06
Original
1581 people have browsed it

这是一款利用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();  
	}  
	 
Copy after login

查询数据库,代码如下:

<?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 
	}  
	
Copy after login

本文链接:

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

source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template