return $this->__call( __FUNCTION__, func_get_args() );
}
+ public function __toString() {
+ if ( $this->conn === null ) {
+ // spl_object_id is PHP >= 7.2
+ $id = function_exists( 'spl_object_id' )
+ ? spl_object_id( $this )
+ : spl_object_hash( $this );
+
+ return $this->getType() . ' object #' . $id;
+ }
+
+ return $this->__call( __FUNCTION__, func_get_args() );
+ }
+
/**
* Error out if the role is not DB_MASTER
*
return $this->conn;
}
- /**
- * @since 1.19
- * @return string
- */
public function __toString() {
- return (string)$this->conn;
+ // spl_object_id is PHP >= 7.2
+ $id = function_exists( 'spl_object_id' )
+ ? spl_object_id( $this )
+ : spl_object_hash( $this );
+
+ $description = $this->getType() . ' object #' . $id;
+ if ( is_resource( $this->conn ) ) {
+ $description .= ' (' . (string)$this->conn . ')'; // "resource id #<ID>"
+ } elseif ( is_object( $this->conn ) ) {
+ // spl_object_id is PHP >= 7.2
+ $handleId = function_exists( 'spl_object_id' )
+ ? spl_object_id( $this->conn )
+ : spl_object_hash( $this->conn );
+ $description .= " (handle id #$handleId)";
+ }
+
+ return $description;
}
/**
return $conn->real_escape_string( (string)$s );
}
- /**
- * Give an id for the connection
- *
- * mysql driver used resource id, but mysqli objects cannot be cast to string.
- * @return string
- */
- public function __toString() {
- if ( $this->conn instanceof mysqli ) {
- return (string)$this->conn->thread_id;
- } else {
- // mConn might be false or something.
- return (string)$this->conn;
- }
- }
-
/**
* @return mysqli
*/
return true;
}
- /**
- * @return string
- */
- public function __toString() {
- return is_object( $this->conn )
- ? 'SQLite ' . (string)$this->conn->getAttribute( PDO::ATTR_SERVER_VERSION )
- : '(not connected)';
- }
-
/**
* @return PDO
*/
* @since 1.31
*/
public function setIndexAliases( array $aliases );
+
+ /**
+ * Get a debugging string that mentions the database type, the ID of this instance,
+ * and the ID of any underlying connection resource or driver object if one is present
+ *
+ * @return string "<db type> object #<X>" or "<db type> object #<X> (resource/handle id #<Y>)"
+ * @since 1.34
+ */
+ public function __toString();
}
/**
$toString = (string)$db;
- $this->assertContains( 'SQLite ', $toString );
+ $this->assertContains( 'sqlite object', $toString );
}
/**