Question:
Beginners PDO?
Devai
2014-06-05 08:06:42 UTC
I have searched for days now, hitting every site I knew of and dozens of new ones - looking for basic tutorials on PDO.

The only working examples I've found ONLY explain setting a string to carry a new PDO session ..
ONE gives an example of reading an array in from the connected database, but it does so by feeding a standard Query into the PDO so I don't see how that is supposed to improve anything.

I can find endless examples for those -like myself- who don't understand much about the programming end, but have a need to do enough of it to maintain a site -Safely- showing how to use the OLD methods to connect, read in, write to (both appending and replacing), and closing connections.

I just need ONE site with such examples using PDO instead.
Three answers:
Devai
2014-06-05 16:07:20 UTC
yes, Abstraction layer, meaning it replaces standard syntax with a simplified - non-specific representation.

But where can I find examples OF that non-specific language?



The example you give would be.. in the old way.

$whatever = mysql_query("SELECT * from x where y");

then reducted by

$myresult=mysql_fetch_array($whatever);



assuming an array of data in a table.



So-- back to my question -- where do I find examples of performing that Same task using PDO prepares?

I don't want to spend a year learning every nuance of PHP and MySQLi to be able to use it for nothing more than reading and writing visitor information securely and storing scores.
tumbleweed_biff
2014-06-05 10:33:28 UTC
"PDO provides a data-access abstraction layer, which means that, regardless of which database you're using, you use the same functions to issue queries and fetch data. PDO does not provide a database abstraction; it doesn't rewrite SQL or emulate missing features. You should use a full-blown abstraction layer if you need that facility. "



http://www.php.net/manual/en/intro.pdo.php
Chris
2014-06-05 09:41:02 UTC
According to this:

http://www.php.net/manual/en/intro.pdo.php



"PDO provides a *data-access* abstraction layer, which means that, regardless of which database you're using, you use the same functions to issue queries and fetch data."



In other words, PDO does not mean you don't need "SELECT * FROM x" stuff any longer.



What it does is replace database specific commands like mysqli_query and the like with generic commands.



So unless I'm completely misunderstanding you, you're looking for improvement in the wrong place.



Not sure whether there's something like db.select("*").from(table).where(id = 3) available for PHP.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...