PDO data insertion problems this post was last edited by zhuzhaodan from 2013-06-12:45:08 $ dsn & nbsp; mysql: hostlocalhost; dbnametest1; $ db & nbsp; new & nbsp; PDO ($ dsn, root, array (PDO: mys pdo data insertion problem
This post was last edited by zhuzhaodan at 11:45:08
$ Dsn = 'MySQL: host = localhost; dbname = test1 ';
$ Db = new PDO ($ dsn, 'root', '', array (PDO: MYSQL_ATTR_INIT_COMMAND => 'set names utf8 '));
Foreach ($ B as $ k => $ v ){
$ Db-> exec ('Insert INTO siji (en, cn) VALUES ($ v [0], $ v [1]) ');
$ B is a 2 array with some string information
1. Why does VALUES ($ v [0], $ v [1]) write and insert data in this way? Change the variable to a specific value. how can I modify it?
2. the query statement in the exec () function is more efficient with single quotes, because variable parsing is not required, isn't it?
3. he failed to insert the database, so I used
Try ($ db-> exec) catch (PDOexception e) {echo e. getMessage ();} why is there no error message?
Share:
------ Solution --------------------
"Insert into siji (en, cn) VALUES ('$ v [0]', '$ v [1]')"