PHP Classes
elePHPant
Icontem

connect to pdo and display results of queries: I would like a PDO connection to a mysql db & show query results

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  All requests RSS feed  >  connect to pdo and display results of queries  >  Request new recommendation  >  A request is featured when there is no good recommended package on the site when it is posted. Featured requests  >  No recommendations No recommendations  

connect to pdo and display results of queries

Edit

Picture of Debbie Schmidt by Debbie Schmidt - 3 months ago (2015-10-20)

I would like a PDO connection to a mysql db & show query results

This request is clear and relevant.
This request is not clear or is not relevant.

+1

I'm trying to move to PDO and would like a way to do this. to make a connection to a mysql db, execute queries and then display the results of the query in table or list, or array.

Ask clarification

1 Recommendation

Full DB-PDO abstraction: Store and retrieve database data as objects

This recommendation solves the problem.
This recommendation does not solve the problem.

+2

Picture of Dave Smith by Dave Smith Reputation 5955 - 3 months ago (2015-10-20) Comment

I was torn between an older package that allows you to return the object as an array or a newer package that is still being maintained but deals with objects as PDO was meant to. I think if you are going to be working with PDO, then you should probably start thinking in terms of objects instead of arrays, so I went with the newer class as a recommendation.

  • 5 Comments
  • 1. Picture of Pierre Delporte by Pierre Delporte package author package author - 3 months ago (2015-10-20) Reply

    Thanks Dave for the recommendation. @Debbie, if you need support, let me know, and I will be pleased to try to help you.

  • 2. Picture of Debbie Schmidt by Debbie Schmidt - 3 months ago (2015-10-20) Reply

    Thank you both for your help. I'll take a look and holler if I get stuck. I'm doing this between jobs (and life) and trying to learn this piecemeal is difficult. It's good to know there's a resource available!

  • 3. Picture of Debbie Schmidt by Debbie Schmidt - 3 months ago (2015-10-22) in reply to comment 1 by Pierre Delporte Reply

    Hi Pierre, Thanks for your offer of help. I find I am getting an error:

    SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES)' in R:\wamp\www\test\full-db-pdo-abstract-2015-10-02\DB.php on line 140.

    I've looked at line 140:

    $this->oPdo = new PDO('mysql:dbname=' . $this->db . ';host=' . $this->host . ';', $this->user, $this->pass, array(PDO::ATTR_PERSISTENT=> true));

    But it seems to be ok. I've researched the error and made sure that localhost has all privileges. Not sure where to look next... Any help would be appreciated.

    Let me know if you want me to use email or your support forum page. Not sure what etiquette is for this. Thanks!

  • 4. Picture of Pierre Delporte by Pierre Delporte package author package author - 3 months ago (2015-10-23) in reply to comment 3 by Debbie Schmidt Reply

    Hi Debbie,

    I think that the error that you received is because you did not supply any password. Could you please show us the way you are initializing the connection ?

    It should be something like : $dblink = DB::getInstance(HOST, USER, PASSWORD, DBNAME, TYPEDB);

    where HOST, USER, PASSWORD, DBNAME and TYPEDB are all defined constants :

    define ('HOST', 'localhost'); define ('USER', 'root'); define ('PASSWORD', 'mypassword'); define ('DBNAME', 'mydb'); define('TYPEDB', 'mysql');

    Hope it helps.

    Yours.

  • 5. Picture of Pierre Delporte by Pierre Delporte package author package author - 3 months ago (2015-10-23) in reply to comment 3 by Debbie Schmidt Reply

    Debbie, my email is in the example file ;)


Recommend package
: 
: