admin管理员组文章数量:1123405
I use php to connect to it. The sql query: "SELECT * FROM "AE"."vw2k_DetFactura limit 2". The problem, just a few fields are correctly retrieved, while the others are null. Fields like "fecFactura", "totalFactura" and so on, has defined values, but doing the query from php, no values are given. The data fetched from DBeaver:
this is the database connection logic:
<?php
namespace App\Services\HanaDb;
use PDO;
use PDOException;
class Connector
{
private $user = "SAP";
private $pass = '<password>';
private $host = '<hana server ip>';
private $charset = 'utf8mb4'; // Charset
private $port = 30015;
private $driver = "HANADB"; //"HDBODBC";
private $db_name = "AE";
///usr/sap/hdbclient
private $driverpath = "/home/aguavista/sap/hdbclient/libodbcHDB.so";
// Data Source Name
private $options = [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, // Error handling mode
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, // Fetch associative arrays by default
PDO::ATTR_EMULATE_PREPARES => false, // Disable emulated prepared statements
];
public $pdo = null;
public $ERROR = NULL;
public function __construct($db_name = 'AE')
{
$this->db_name = $db_name;
}
public function obtenerConn()
{
try {
$dsn = $this->getDsn();
$this->pdo = new PDO($dsn, $this->user, $this->pass, $this->options); // Create a PDO instance
return $this->pdo; // If successful
} catch (PDOException $e) {
$this->ERROR = $e->getMessage();
return null;
}
}
private function conectar()
{
try {
$dsn = $this->getDsn();
$this->pdo = new PDO($dsn, $this->user, $this->pass, $this->options); // Create a PDO instance
return true; // If successful
} catch (PDOException $e) {
$this->ERROR = $e->getMessage();
return false;
}
}
private function getDsn()
{
$dsn = '';
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
$dsn = "odbc:DRIVER=HDBODBC;SERVERNODE=$this->host:$this->port;DATABASE=$this->db_name;charset=$this->charset";
} else {
$dsn = "odbc:DRIVER=$this->driverpath;SERVERNODE=$this->host:$this->port;DATABASE=$this->db_name;charset=$this->charset";
}
return $dsn;
}
function consultar($sql)
{
$OK = $this->conectar();
if ($OK) { // Prepare and execute the query
$stmt = $this->pdo->query($sql);
// Fetch all the results
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
return $rows;
} else return NULL;
}
function insertar($table, $fields)
{
$OK = $this->conectar();
if ($OK) { // Prepare and execute the query
$var_names = array_map(function ($a) {
return ":f" . $a;
}, $fields);
$statement = $this->pdo->prepare('INSERT INTO ' . $table . ' (' . implode(',', array_keys($fields)) . ')
VALUES (' . implode(',', $var_names) . ')');
$data = array_combine($var_names, array_values($fields));
$statement->execute($data);
} else return NULL;
}
function ejecutar($sql)
{
$OK = $this->conectar();
if ($OK) { // Prepare and execute the query
$statement = $this->pdo->exec($sql);
return $statement;
} else return NULL;
}
}
Usage:
$hana = new Connector($dbname);
$result = $hana->consultar($sql);
dd($result[0]);
Output
Structure
is there any issue about parsing data? or is it needed to set some special attribute?
本文标签: phphana database Not null fields are retrieved as nullStack Overflow
版权声明:本文标题:php - hana database: Not null fields are retrieved as null - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736567823a1944730.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论