# [PATCH] Generate warning when using PDO::setAttribute() and ATTR_PERSISTENT

- Thread: https://externals.io/message/32982
- Original archive: https://news-web.php.net/php.internals/32982
- Started by Ben Ramsey on 2007-10-26T17:38:04+00:00
- Messages: 4
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #32982 — Ben Ramsey — 2007-10-26T17:38:04+00:00

URL: https://externals.io/message/32982#32982

For a while, we were scratching our heads over why persistent
connections were not being created when using PDO_OCI, even though we
were explicitly calling PDO::setAttribute() to set PDO::ATTR_PERSISTENT.

My colleague Brian DeShong further explains the issue on his blog:
http://www.deshong.net/?p=61

"You must set PDO::ATTR_PERSISTENT => true in the array of options you
pass to the PDO constructor! If you call
$pdo->setAttribute(PDO::ATTR_PERSISTENT, true) after the instantiation
of the object, you won’t be using persistent connections."

He goes on to say: "It’d be nice if PDO::setAttribute() raised a warning
if you try to set PDO::ATTR_PERSISTENT, by the way."

I'm submitting the attached patch to do just that. :-)

-- 
Ben Ramsey
http://benramsey.com/

---

## #32983 — Andi Gutmans — 2007-10-26T18:44:31+00:00

URL: https://externals.io/message/32982#32983 · In reply to: #32982

Why is it not an if() statement?

> -----Original Message-----
> From: Ben Ramsey [mailto:ramsey@php.net]
> Sent: Friday, October 26, 2007 10:38 AM
> To: internals@lists.php.net
> Subject: [PHP-DEV] [PATCH] Generate warning when using
> PDO::setAttribute() and ATTR_PERSISTENT
> 
> For a while, we were scratching our heads over why persistent
> connections were not being created when using PDO_OCI, even though we
> were explicitly calling PDO::setAttribute() to set
> PDO::ATTR_PERSISTENT.
> 
> My colleague Brian DeShong further explains the issue on his blog:
> http://www.deshong.net/?p=61
> 
> "You must set PDO::ATTR_PERSISTENT => true in the array of options you
> pass to the PDO constructor! If you call $pdo-
> > […]
> the object, you won’t be using persistent connections."
> 
> He goes on to say: "It’d be nice if PDO::setAttribute() raised a
> warning if you try to set PDO::ATTR_PERSISTENT, by the way."
> 
> I'm submitting the attached patch to do just that. :-)
> 
> --
> Ben Ramsey
> http://benramsey.com/

---

## #32984 — Ben Ramsey — 2007-10-26T18:50:37+00:00

URL: https://externals.io/message/32982#32984 · In reply to: #32983

> Why is it not an if() statement?

It can be an if() statement. I added it as a switch in the expectation
that other attributes might be added to it in the future.

-- 
Ben Ramsey
http://benramsey.com/

---

## #32985 — Lukas Kahwe Smith — 2007-10-26T18:52:22+00:00

URL: https://externals.io/message/32982#32985 · In reply to: #32983

> Why is it not an if() statement?
>
> > […]

Personally I find the entire attribute stuff in PDO a gigantic mess  
which I said before the first release. Some things are not attributes  
you can set, some of the things you cannot set at runtime etc. So  
something are "attributes" of the connections, others are options and  
yet others can only be set at connect time, so they should not even  
be accepted as valid parameters to whatever set*() method as you  
point out as it will have no effect. This should really be cleaned up  
one day (PDO2?)

regards,
Lukas
