I need to connect to a db oracle, for that I'm using the following code!
<?php class ConnectionDBTOAD{
private static $conn=null;
private static $server = "mi host";
private static $db_username = "mi usuario";
private static $db_password = "contraseña";
private static $service_name = "serviciox";
private static $sid = "serviciox";
private static $port = 1521;
private static $dbtns = "(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = $server)(PORT = $port)) (CONNECT_DATA = (SERVICE_NAME = $service_name) (SID = $sid)))";
public static function OpenBDTOAD(){
if (self::$conn==null) {
try{
self::$conn = new PDO("oci:dbname=" . self::$dbtns . ";charset=utf8", self::$db_username, self::$db_password, array( PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC));
}
catch (PDOException $e) {
echo $e->getMessage();
}
return self::$conn;
}
}
public static function CloseBDTOAD(){
self::$conn=null;
}}?>
However, in the browser I get the message
Fatal error: Constant expression contains invalid operations in C: \ xampp \ htdocs \ cycle \ model \ connectiondt.php on line 9
that is, the error is right on this line
private static $dbtns = "(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = $server)(PORT = $port)) (CONNECT_DATA = (SERVICE_NAME = $service_name) (SID = $sid)))";
I have already modified the php.ini file by enabling
extension = php_pdo_oci.dll
I have also tried to place the connection outside of a class and I get the same error!