pdo:connecting_to_mysql
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
pdo:connecting_to_mysql [2016/10/14 08:27] – created peter | pdo: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 | + | Create |
+ | |||
+ | 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:// | 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:// | ||
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. | + | 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)