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