A moment ago post the following question! Problems with PDO and PHP
Once the code in the connection file has been corrected, the following error appears!
could not find driver
Fatal error: Uncaught Error: Call to a member function setAttribute () on null in C: \ xampp \ htdocs \ cycle \ model \ model.gestiones.php: 19 Stack trace: # 0 C: \ xampp \ htdocs \ cycle \ view \ index.php (12): Management :: query () # 1 {main} thrown in C: \ xampp \ htdocs \ cycle \ model \ model.gestiones.php on line 19
the code I have in the model.gestiones.php file is as follows
<?php
header("Content-Type: text/html;charset=utf-8");
class Gestiones
{
function consulta(){
$pdo= ConnectionDBTOAD::OpenBDTOAD();
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$pdo->exec("SET CHARACTER SET utf8");
$sql=" aqui va la consulta SQL";
$query= $pdo->prepare($sql);
$query->execute();
$result=$query->fetchALL(PDO::FETCH_BOTH);
ConnectionDBTOAD::CloseBDTOAD();
return $result;
}
}?>
I do not know why the error appears because the code has not been modified (this file is a copy / paste of a project that was delivered yesterday, with the difference that it was a connection to mysql.)
As I said in the previous question! I have already modified the php.ini file by removing the semicolon (;) in the line where this extension = php_pdo_oci.dll.
Thank you in advance for your answers! I'll be attentive!
PDT: this is the connection class code
<?php class ConnectionDBTOAD{
private static $conn=null;
private static $server = "host";
private static $db_username = "user";
private static $db_password = "contraseña";
private static $service_name = "servicioX";
private static $sid = "servicioX";
private static $port = 1521;
private static $dbtns;
public static function OpenBDTOAD(){
if (self::$conn==null) {
self::$dbtns = "(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = " . self::$server . ")(PORT = " . self::$port . ")) (CONNECT_DATA = (SERVICE_NAME = " . self::$service_name . ") (SID = " . self::$sid . ")))";
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;
}}?>