[英]My Parsing method return null (oci_parse() method)
I want to create a class that uses some OCI methods to connect to ORACLE databases.我想创建一个 class,它使用一些 OCI 方法连接到 ORACLE 数据库。
But my Parse() method is null when I call it and my FetchArray() method returns nothing但是当我调用它时我的 Parse() 方法是 null 并且我的 FetchArray() 方法没有返回任何内容
Database php class:数据库 php class:
class Database
{
/**
* @var string
*/
private string $login;
/**
* @var string
*/
private string $password;
/**
* @var string
*/
private string $description;
/**
* @var
*/
private $connection;
/**
* @var
*/
private $stmt;
public function __construct(string $login, string $password, string $description)
{
$this->login = $login;
$this->password = $password;
$this->description = $description;
}
public function Connection($character_set = null, $session_mode = null)
{
$this->connection = oci_connect($this->login, $this->password, $this->description, $character_set, $session_mode);
}
public function Parse(string $sql)
{
$this->stmt = oci_parse($this->connection, $sql);
}
public function Execute()
{
oci_execute($this->stmt);
}
Test Page.php:测试页.php:
$database = new Database($login, $pass, $descr);
$database->Connection();
if ($database->IsConnected()) {
$database->Parse($sql);
$database->Execute();
while ($row = $database->FetchArray(OCI_BOTH) != false) {
// Use the uppercase column names for the associative array indices
echo $row[0] . " and " . $row['EMAIL'] . " are the same<br>\n";
echo $row[1] . " and " . $row['NAME'] . " are the same<br>\n";
}
$database->Disconnection();
} else {
echo 'Error';
}
Currently, the connection to the database is successful.目前,连接数据库是成功的。
FetchArray method:获取数组方法:
public function FetchArray($mode = null)
{
oci_fetch_array($this->stmt, $mode);
}
I think I found a problem.我想我发现了一个问题。 In your while condition, you probaby missed couple brackets, to make it comparing result of fetch to row data to boolean false.在您的 while 条件下,您可能错过了一对括号,以使其将提取结果与行数据与 boolean false 进行比较。
$database = new Database($login, $pass, $descr);
$database->Connection();
if ($database->IsConnected()) {
$database->Parse($sql);
$database->Execute();
while (($row = $database->FetchArray(OCI_BOTH)) != false) {
// Use the uppercase column names for the associative array indices
echo $row[0] . " and " . $row['EMAIL'] . " are the same<br>\n";
echo $row[1] . " and " . $row['NAME'] . " are the same<br>\n";
}
$database->Disconnection();
} else {
echo 'Error';
}
This line is updated:此行已更新:
while (($row = $database->FetchArray(OCI_BOTH)) != false) {
I think it would be also safe to remove type casting from fetch function我认为从 fetch function 中删除类型转换也是安全的
public function FetchArray($mode = null):
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.