user3106858
user3106858

Reputation: 35

Having issues with Mysql PDO In a Class

Well basically I'm learning PDO & Classes, and I've honestly been tampering with this simple code for about 2 days now trying to get it to work.

Basically what I'm trying to do is establish a PDO connection, and use it globally in a class.

I thought it would be a lot simpler this but I'm still having issues. I have previously made it successful up to the point of completing a query but wouldn't return any value. So I tampered with it more, and now I'm at this code currently, and I'm having issues with it:

1) connecitng to the database 2) returning the query

(I for some reason wasn't able to find out how to use the code tags but this is the main idea of my code/class.)

Remember, im learning still so all help and suggestions will be appreciated. http://pastebin.com/UbyUKfzM

I put it as a pastebin because I couldn't figure out how to put the code on here.

The code is a little sloppy and messy right now because I had to remove it from my script to make it testable for your use.

Sorry if I missed anything. Or made this more confusing then it should be. Thanks again for your help everyone!

-Side note: I've looked into other articles / forum topics about this and they either didn't help me or I had an issue with understanding / implementing it.

I don't expect you to recode my code, I just need to know where I messed up & How I should fix it.

Upvotes: 0

Views: 46

Answers (1)

Fraz0r
Fraz0r

Reputation: 396

Call $this->dbhconnection() from within your constructor, and then access the connection with $this->dbh instead of $this->dbhconnection() inside your bar() method.

I know you mentioned that you didn't want anyone to rewrite your code, but, I have to say, a class that takes that many required arguments is extremely cumbersome.

Upvotes: 1

Related Questions