I have installed PHP and ORACLE on windows 7.
Then I connected PHP to ORACLE using PDO, like this:
$tns = "(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = oradb)
)
)";
$db_username = "C##OTO_USER";
$db_password = "oto_user_pass";
try{
$conn = new PDO('oci:dbname='.$tns.';charset=UTF8',$db_username,$db_password);
}catch(PDOException $e){
echo ($e->getMessage());
}
After connection, I try to query some table:
$sth = $conn->prepare("SELECT * FROM mytable");
$sth->execute();
if ($sth->errorInfo()[2] === NULL) { // if no error, print returned result
$res = $sth->fetchAll(PDO::FETCH_ASSOC);
var_dump($res);
}
else { // if some error, print error message
echo $sth->errorInfo()[2];
}
Strange, is that query returns empty array, as if there is no rows in "mytable", though there are rows, if run SELECT * FROM mytable
in SQL DEVELOPER
, returned all rows.
Also, if make error consciously, then PHP PDO returns error, for example try selecting from non existing table "mytable_bla", gives:
OCIStmtExecute: ORA-00942: table or view does not exist (ext\pdo_oci\oci_statement.c:148)
So, PDO connected to ORACLE DB, but don't sees rows from table, when actually there are rows in table.
What may be caused this?
EDIT
I noticed that PDO don't sees new created table rows, but sees renamed table rows.
For example RENAME mytable TO mytable2
, then PDO sees rows from mytable2