Home > Backend Development > PHP Tutorial > PDO插入数据的有关问题

PDO插入数据的有关问题

WBOY
Release: 2016-06-13 12:45:31
Original
797 people have browsed it

PDO插入数据的问题

本帖最后由 zhuzhaodan 于 2013-06-12 11:45:08 编辑
	$dsn = 'mysql:host=localhost;dbname=test1';<br />
	$db = new PDO($dsn,'root','',array(PDO::MYSQL_ATTR_INIT_COMMAND => 'set names utf8'));<br />
	foreach($b as $k=>$v){<br />
		$db->exec('INSERT INTO siji (en,cn) VALUES ($v[0],$v[1])');
Copy after login

$b是一个2为数组里面有一些字符串信息
1.为什么VALUES ($v[0],$v[1])这样写插入不进去数据?把变量改为具体值就可以了,怎么修改呢
2.exec()函数里面的查询语句用单引号效率更高一些,因为不用解析变量,是不是啊
3.他没成功插入数据库,那么我用
try($db->exec) catch(PDOexception e){echo e.getMessage();}为什么什么错误信息也没有呢?
Related labels:
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