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 ...)