Register Advertise with usHelp Desk Today's Posts Search

Closed Thread
Thread Tools Search this Thread
Unread 11th Jul 2015, 11:36 AM   #1
Arthur
 
Join Date: 2014
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default
PDO One Time Connection?
Share on: 
fb share twitter share gplus share more share

Hi there,

Is this real that I can connect one time to mysql using PDO? I mean is that right to do that?
If I use the autoloader and I call every time the DATABASE class I'm connecting every time when I call to database class?
exma is offline  
Unread 12th Jul 2015, 11:54 AM   #2
Bananas are Yellow!
Registered Member
War Room Member
 
David Beroff's Avatar
 
Join Date: 2013
Location: Wyoming, PA, USA
Posts: 1,046
Thanks: 2,549
Thanked 1,600 Times in 928 Posts
Blog Entries: 4
Default
Re: PDO One Time Connection?
Share on: 
fb share twitter share gplus share more share

Yes, PDO is the layer you should be using:
PHP: PDO - Manual

Put MY voice on YOUR video: AwesomeAmericanAudio.com
David Beroff is offline  
Unread 12th Jul 2015, 12:06 PM   #3
Arthur
 
Join Date: 2014
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default
Re: PDO One Time Connection?
Share on: 
fb share twitter share gplus share more share

Originally Posted by David Beroff View Post

Yes, PDO is the layer you should be using:
PHP: PDO - Manual
What do you mean "PDO is the layer"?
exma is offline  
Unread 12th Jul 2015, 04:08 PM   #4
Bananas are Yellow!
Registered Member
War Room Member
 
David Beroff's Avatar
 
Join Date: 2013
Location: Wyoming, PA, USA
Posts: 1,046
Thanks: 2,549
Thanked 1,600 Times in 928 Posts
Blog Entries: 4
Default
Re: PDO One Time Connection?
Share on: 
fb share twitter share gplus share more share

Originally Posted by exma View Post

What do you mean "PDO is the layer"?
PHP offers several database abstraction layers, of which, PDO is generally recommended.

Put MY voice on YOUR video: AwesomeAmericanAudio.com
David Beroff is offline  
Unread 12th Jul 2015, 10:08 PM   #5
Arthur
 
Join Date: 2014
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default
Re: PDO One Time Connection?
Share on: 
fb share twitter share gplus share more share

Originally Posted by David Beroff View Post

PHP offers several database abstraction layers, of which, PDO is generally recommended.
Yeah I know, but the question if I can connect one time to DB and if its right to do that?
The second question: if I make DATABASE class using PDO and I call everytime to this class so I reconnect everytime to DB?
exma is offline  
Unread 13th Jul 2015, 07:47 AM   #6
Bananas are Yellow!
Registered Member
War Room Member
 
David Beroff's Avatar
 
Join Date: 2013
Location: Wyoming, PA, USA
Posts: 1,046
Thanks: 2,549
Thanked 1,600 Times in 928 Posts
Blog Entries: 4
Default
Re: PDO One Time Connection?
Share on: 
fb share twitter share gplus share more share

Originally Posted by exma View Post

Yeah I know, but the question if I can connect one time to DB and if its right to do that?
Yeah; why not? No one cares if you connect once or a thousand times.

Originally Posted by exma View Post

The second question: if I make DATABASE class using PDO and I call everytime to this class so I reconnect everytime to DB?
I'm not sure why you need to create another layer around PDO. Just call it directly; we're talking maybe two or three lines of code.

In my own software, I connect to the database once at the beginning of the PHP invocation, then I pass the open database handle to any function that needs it, and finally close it ("$db = NULL;") at the very end.

Put MY voice on YOUR video: AwesomeAmericanAudio.com
David Beroff is offline  
Unread 14th Jul 2015, 01:22 PM   #7
Arthur
 
Join Date: 2014
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default
Re: PDO One Time Connection?
Share on: 
fb share twitter share gplus share more share

Originally Posted by David Beroff View Post

Yeah; why not? No one cares if you connect once or a thousand times.
Someone says me if I connect one time I'm calling one time the PDO class and run it only one time all processes. Then I just use the is set process.

Originally Posted by David Beroff View Post

I'm not sure why you need to create another layer around PDO. Just call it directly; we're talking maybe two or three lines of code.

In my own software, I connect to the database once at the beginning of the PHP invocation, then I pass the open database handle to any function that needs it, and finally close it (" = NULL;") at the very end.
I do that because I build all system on OOP and I'm use the autoloader to call classes and methods. Then I can use the specific method like a method to get a row. What I do its use only one line of code to run a query and all filtering on the query. Its to save a processes on server and code lines. I'm writing only one time all method to get a row and then I use every time only one row like:

PHP Code:
Database::getrow("SELECT * FROM database WHERE users = ?", ['usernames_array']); 
exma is offline  
Unread 14th Jul 2015, 04:14 PM   #8
Bananas are Yellow!
Registered Member
War Room Member
 
David Beroff's Avatar
 
Join Date: 2013
Location: Wyoming, PA, USA
Posts: 1,046
Thanks: 2,549
Thanked 1,600 Times in 928 Posts
Blog Entries: 4
Default
Re: PDO One Time Connection?
Share on: 
fb share twitter share gplus share more share

OK. So you're good to go.

Put MY voice on YOUR video: AwesomeAmericanAudio.com
David Beroff is offline  
Closed Thread


Bookmarks

Tags
connection, pdo, time


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT -6. The time now is 04:06 PM.