PDO link mysql learning _ MySQL

Source: Internet
Author: User
Tags dsn
PDO link mysql learning
 // Dsn: // dsn01 $ dsn = 'MySQL: host = localhost; dbname = mysql'; // $ dsn = 'MySQL: host = localhost; dbname = mysql [; port = 3306; charset = UTF8] ';/** dsn02 $ dsn = 'uri: file: // C:/xampp/htdocs/pdo/config.txt'character config.txt: mysql: host = localhost; dbname = mysqllinux and windows are feasible $ dsn = 'uri: file: // home/pdo/config.txt '; * // ** dsn03 $ dsn = 'mydb'; php. add: pdo. dsn. mydb = 'MySQL: host = localhost; dbname = mysql' */$ user = 'Root'; $ pwd = ''; // if the attempt to connect to the requested database fails, PDO ::__ construct () throws a PDO exception (PDOException ). Try {$ link = new PDO ($ dsn, $ user, $ pwd);} catch (PDOException $ e) {echo 'connection failed :'. $ e-> getMessage () ;}$ userSet = $ link-> query ('select * from user'); print_r ($ userSet );

 BeginTransaction ();/* do something */if (true) {/* submit changes */$ dbh-> commit ();} else {/* identifies errors and rolls back changes */$ dbh-> rollBack ();} /* the database connection is now returned to the automatic submission mode * // ** note that some databases, including MySQL, have DDL statements such as deleting or creating data tables in a transaction, it automatically leads to an implicit commit. Implicit commit will not roll back any changes within this transaction range. For more information, see http://dev.mysql.com/doc/refman/5.0/en/implicit-commit.html */

 Prepare ('Call puree_fruit (?) '); $……-> BindParam (1, $ color, PDO: PARAM_STR | PDO: PARAM_INPUT_OUTPUT, 12); $……> execute (); print ("After pureeing fruit, the color is: $ color ");

(To Be Continued ...)

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.