8

Is there a way to get a unique connection id of a PDO connection to mysql?

mosch
  • 1,005
  • 1
  • 12
  • 24
  • What do you want to do with this id? E.g.: Compare objects? Find correlating entries in mysql general query log? Implements some kind of connection pooling? ...? – VolkerK Aug 26 '10 at 09:08

1 Answers1

15

Try sth like this.

print_r($dbh->query('SELECT CONNECTION_ID()')->fetch(PDO::FETCH_ASSOC));

you can use a regular query to execute the CONNECTION_ID() mysql command to get the connection ID.

See the mySQL manual for more

Jürgen Hörmann
  • 462
  • 4
  • 17