dtdb99743 2016-10-18 21:12
浏览 77

PHP连接到ORACLE,但无法访问表行

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

  • 写回答

1条回答 默认 最新

  • duagfgfn1981 2016-12-28 08:41
    关注

    Try to attach the scheme name to your table name like so:

    $sth = $conn->prepare("SELECT * FROM yourSchemeName.mytable");
    
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。