Can't connect to HyperFileSQL using php with odbc

1.9k views Asked by At

I have a database with HyperFileSQL and I want to access this database via php. If I use IODBC to connect with iodbc.ini, it works !!! But when I want to connect from php with odbc it doesn't I have this in return :

SQLSTATE[0] SQLDriverConnect: 0 [unixODBC]I

When I connect to the database from iodbc with this line :

iodbctest DSN=DACHFSQL  

It works !

this is the my code :`

try{
    $conn = new PDO("odbc:Driver={HFSQL};DSN={DACHFSQL};Server=$db_server_name;Port=$port;Database=$database;",$user,$password);
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $sql = "SELECT * FROM contacts";
    $res_select = $conn->prepare($sql);
    $res_select->execute();
} catch (PDOException $e) {
echo 'Échec lors de la connexion : ' . $e->getMessage();}

I don't know why I can't connect... Pleaze help !

2

There are 2 answers

1
Ben On

You need to compile php with iodbc support (instead of odbc).

2
Vince On

This code works for me (WD 21).

$hf_hostname = "localhost";
$hf_port = "4900";
$hf_database = "MyDb";
$hf_user = "admin";
$hf_password = "";
$hf_dsn = sprintf("odbc:DRIVER={HFSQL};Server Name=%s;Server Port=%s;Database=%s;UID=%s;PWD=%s;", $hf_hostname, $hf_port, $hf_database, $hf_user, $hf_password);
$hf_dbh = new PDO($hf_dsn);

HTH