User Tools

Site Tools


pdo:connecting_to_mysql

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
pdo:connecting_to_mysql [2016/10/14 08:27] – created peterpdo:connecting_to_mysql [2020/07/15 09:30] (current) – external edit 127.0.0.1
Line 1: Line 1:
 ====== PDO - Connecting to MySQL ====== ====== PDO - Connecting to MySQL ======
  
-create a new PDO object.  PDO's constructor takes at most 4 parameters, DSN, username, password, and an array of driver options.+Create a new PDO object. 
 + 
 +PDO's constructor takes at most 4 parameters, DSN, username, password, and an array of driver options.
  
 A DSN is basically a string of options that tell PDO which driver to use, and the connection details... You can look up all the options here [[http://www.php.net/manual/en/ref.pdo-mysql.connection.php|PDO MYSQL DSN]]. A DSN is basically a string of options that tell PDO which driver to use, and the connection details... You can look up all the options here [[http://www.php.net/manual/en/ref.pdo-mysql.connection.php|PDO MYSQL DSN]].
Line 12: Line 14:
 **NOTE**: If you get an error about character sets, make sure you add the charset parameter to the DSN.  Adding the charset to the DSN is very important for security reasons, most examples you'll see around leave it out.  MAKE SURE TO INCLUDE THE CHARSET! **NOTE**: If you get an error about character sets, make sure you add the charset parameter to the DSN.  Adding the charset to the DSN is very important for security reasons, most examples you'll see around leave it out.  MAKE SURE TO INCLUDE THE CHARSET!
  
-You can also pass in several driver options as an array to the fourth parameters.  I recommend passing the parameter which puts PDO into exception mode, which I will explain in the next section.  The other parameter is to turn off prepare emulation which is enabled in MySQL driver by default, but really should be turned off to use PDO safely and is really only usable if you are using an old version of MySQL.+You can also pass in several driver options as an array to the fourth parameters. 
 + 
 +I recommend passing the parameter which puts PDO into exception mode, which I will explain in the next section. 
 + 
 +The other parameter is to turn off prepare emulation which is enabled in MySQL driver by default, but really should be turned off to use PDO safely and is really only usable if you are using an old version of MySQL.
  
 <code php> <code php>
pdo/connecting_to_mysql.1476433665.txt.gz · Last modified: 2020/07/15 09:30 (external edit)

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki