pdo connection database, query and save data to mysql_PHP tutorial

WBOY
Release: 2016-07-13 17:04:54
Original
1086 people have browsed it

This is an operation example using php+pdo+mysql, which uses pdo to connect to the database, query and save data to mysql.

This is an operation example using php tutorial + pdo + mysql tutorial, which is to use pdo to connect to the database tutorial to query and save data into mysql.

pdo data saving

$pdo = new pdo("mysql:host=localhost;dbname=db_demo","root","");
if($pdo -> exec("insert into db_demo(name,content) values('title','content')")){
echo "Insertion successful!";
echo $pdo -> lastinsertid();
}
?>

Query database

$pdo = new pdo("mysql:host=localhost;dbname=db_demo","root","");
$rs = $pdo -> query("select * from test");
while($row = $rs -> fetch()){
print_r($row);
}
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/630826.htmlTechArticleThis is an operation example using php+pdo+mysql, which uses pdo to connect to the database, query and save The data is stored in mysql. This is an operation example using php tutorial + pdo + mysql tutorial...
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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template