Есть ли способ получить уникальный идентификатор соединения PDO-соединения с mysql?
Попробуй так.
print_r($dbh->query('SELECT CONNECTION_ID()')->fetch(PDO::FETCH_ASSOC));
вы можете использовать обычный запрос для выполнения команды CONNECTION_ID () mysql для получения идентификатора соединения.
Подробнее см. В руководстве mySQL.
/* Define Data */ define("DB_HOST","localhost"); define("DB_NAME","DB_NAME"); define("DB_USERNAME","DB_USERNAME"); define("DB_PASSWORD","DB_PASSWORD"); define("DB_CHARSET","utf8"); class conn_db { private static $main_var = NULL; function __construct() { $this->db_host=DB_HOST; $this->db_name=DB_NAME; $this->db_username=DB_USERNAME; $this->db_pass=DB_PASSWORD; if (!self::$main_var) { self::$main_var= new PDO("mysql:host=".$this->db_host.";dbname=". $this->db_name.";charset=".DB_CHARSET."", $this->db_username, $this->db_pass); self::$main_var->setAttribute(PDO::ATTR_EMULATE_PREPARES, 1); self::$main_var->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); } return self::$main_var; } /*fetch results*/ public static function get_results($getquery,$param=NULL,$type=NULL) { try { $PDO_connect=self::$main_var; $data_query=$PDO_connect->prepare($getquery); if($param!=NULL) { foreach($param as $param_name => &$param_value) { $data_query->bindParam(':'.$param_name, $param_value); } } $data_query->execute(); if($type==NULL) { $fetch_type=PDO::FETCH_OBJ; } if($type=="_A") { $fetch_type=PDO::FETCH_ASSOC; } $fetch_data=$data_query->fetchAll($fetch_type); return $fetch_data; } catch( PDOException $Exc ) { echo $Exc->getMessage(); die(); return FALSE; } } /*action results such like insert , update,delete and alter return value last insert row id */ public static function query($getquery,$param=NULL) { try { $PDO_connect=self::$main_var; $data_query=$PDO_connect->prepare($getquery); /*for insertion*/ if (strpos(strtolower($getquery),'insert') !== false) { $data_query->execute($param); return $PDO_connect->lastInsertId(); } /*for update,delete,etc*/ else{ if($param!=NULL) { foreach($param as $param_name => &$param_value) { $data_query->bindParam(':'.$param_name, $param_value); } } $data_query->execute(); return $data_query; } } catch( PDOException $Exc ) { echo $Exc->getMessage(); die(); return FALSE;} } } $GLOBALS['conn_db']=new conn_db();