PDO data insertion problems

Source: Internet
Author: User
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]')"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.