Menu
Forums
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Trending
What's new
New posts
New profile posts
Latest activity
Members
Current visitors
New profile posts
Search profile posts
Upgrades
Log in
Register
What's new
Search
Search
Search titles only
By:
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Menu
Log in
Register
Navigation
Install the app
Install
More options
Contact us
Close Menu
Forums
Software Development
Programming
Tutorials
[PHP] How to use PDO
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="josilol" data-source="post: 236919" data-attributes="member: 38060"><p>Nice! PDO is great and we use it on work, in school etc.</p><p>Here's some pointers and things <em>you could</em> add to make the tutorial even better:</p><p></p><p>Step 1:</p><ul> <li data-xf-list-type="ul">Change the name <em>$config['PDO']['Data']['Source']['Name']</em> to be <em>$config['PDO']['dsn']</em> instead. It's shorter and having an array of an array of an array of an array (did I pull that off right?) just to hold a single string value doesn't make that much sense.</li> <li data-xf-list-type="ul">You should tell something about what<strong> dsn</strong> actually is and how easily you chance between different database systems.</li> </ul><p>Step 2:</p><ul> <li data-xf-list-type="ul">You should add a list on the most common dsn to the different databases available. You should also probably mention that there is a optional options array that you can pass with some additional configuration, some of these may not be altered later once the PDO object has been created.</li> <li data-xf-list-type="ul">There are three different error modes available on PDO, it could be good to know about them. A short description about the different modes and how you change to use them should be enough. Some PHP versions<em> may</em> have different default error mode!<br /> </li> <li data-xf-list-type="ul">It's also a good idea to make sure the Exception message is logged instead of just outputting it especially in a production environment.</li> </ul><p>Step 3:</p><ul> <li data-xf-list-type="ul">Actually you don't have to prepare a statement in PDO, it's good practice but it isn't a requirement. Instead you could use <a href="http://se1.php.net/manual/en/pdo.query.php" target="_blank">http://se1.php.net/manual/en/pdo.query.php</a> in the code example above since there is no data coming from the user. </li> <li data-xf-list-type="ul">Again in your code example, I think $result['first_name']; would generate some sort of error, as fetchAll() is returning an array with the row as a result or FALSE if there are 0 results to fetch. What you actually were looking for is $result[0]['first_name']; which would output the first_name of the first element in the array (the first row that is).</li> <li data-xf-list-type="ul">You should probably add something about the different FETCH styles that are available.</li> <li data-xf-list-type="ul">Some more examples with INSERT, UPDATE, DELETE would be great!</li> </ul></blockquote><p></p>
[QUOTE="josilol, post: 236919, member: 38060"] Nice! PDO is great and we use it on work, in school etc. Here's some pointers and things [I]you could[/I] add to make the tutorial even better: Step 1: [LIST] [*]Change the name [I]$config['PDO']['Data']['Source']['Name'][/I] to be [I]$config['PDO']['dsn'][/I] instead. It's shorter and having an array of an array of an array of an array (did I pull that off right?) just to hold a single string value doesn't make that much sense. [*]You should tell something about what[B] dsn[/B] actually is and how easily you chance between different database systems. [/LIST] Step 2: [LIST] [*]You should add a list on the most common dsn to the different databases available. You should also probably mention that there is a optional options array that you can pass with some additional configuration, some of these may not be altered later once the PDO object has been created. [*]There are three different error modes available on PDO, it could be good to know about them. A short description about the different modes and how you change to use them should be enough. Some PHP versions[I] may[/I] have different default error mode! [*]It's also a good idea to make sure the Exception message is logged instead of just outputting it especially in a production environment. [/LIST] Step 3: [LIST] [*]Actually you don't have to prepare a statement in PDO, it's good practice but it isn't a requirement. Instead you could use [url]http://se1.php.net/manual/en/pdo.query.php[/url] in the code example above since there is no data coming from the user. [*]Again in your code example, I think $result['first_name']; would generate some sort of error, as fetchAll() is returning an array with the row as a result or FALSE if there are 0 results to fetch. What you actually were looking for is $result[0]['first_name']; which would output the first_name of the first element in the array (the first row that is). [*]You should probably add something about the different FETCH styles that are available. [*]Some more examples with INSERT, UPDATE, DELETE would be great! [/LIST] [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
Software Development
Programming
Tutorials
[PHP] How to use PDO
Top