<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: gaël digard</title>
    <description>The latest articles on Forem by gaël digard (@gaeldigard).</description>
    <link>https://forem.com/gaeldigard</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F991090%2F73ee927f-cb4f-4a4d-a2e0-7eb4d11652ab.png</url>
      <title>Forem: gaël digard</title>
      <link>https://forem.com/gaeldigard</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/gaeldigard"/>
    <language>en</language>
    <item>
      <title>How to settle HFSQL connection with ODBC via PDO for Php</title>
      <dc:creator>gaël digard</dc:creator>
      <pubDate>Mon, 02 Jan 2023 09:29:44 +0000</pubDate>
      <link>https://forem.com/gaeldigard/how-to-settle-hfsql-odbc-via-pdo-for-php-3jd6</link>
      <guid>https://forem.com/gaeldigard/how-to-settle-hfsql-odbc-via-pdo-for-php-3jd6</guid>
      <description>&lt;p&gt;I've been struggling for weeks before being able to connect and request an HyperFileSQL (HFSQL) database in PHP, using ODBC via PDO. &lt;/p&gt;

&lt;p&gt;Here's a complete guide tested with &lt;code&gt;PHP 8.0.15&lt;/code&gt;, &lt;code&gt;Apache 2.4.23&lt;/code&gt; and &lt;code&gt;ODBC Drivers 26.0101d&lt;/code&gt;, on &lt;code&gt;Windows 10 Entreprise 64 bits (10.0, build 19044)&lt;/code&gt;.&lt;/p&gt;

&lt;h1&gt;
  
  
  HyperFileSQL
&lt;/h1&gt;

&lt;p&gt;As a reminder, HFSQL is a database engine from the late 80's, developped by a french company named PC SOFT. This company is also responsible for WinDev, WebDev, and many others monstruosities. All that mess is natively Windows compatible, not working really well on Linux.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Source : &lt;a href="https://fr.wikipedia.org/wiki/PC_SOFT" rel="noopener noreferrer"&gt;https://fr.wikipedia.org/wiki/PC_SOFT&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;You'll notice there's no Wiki article about HFSQL, demonstrating its popularity. You barely can find useful information on stackOverflow either, or just some crumbs, that you have to gather, tries after tries.&lt;/p&gt;

&lt;h1&gt;
  
  
  Probable stack reminder
&lt;/h1&gt;

&lt;p&gt;I think it works like that. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fspebrjj99d5t6lus14y1.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fspebrjj99d5t6lus14y1.jpg" alt="Stack explaination of how PDO ODBC AND HFSQL drivers work"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  ODBC driver on the HFSQL server
&lt;/h1&gt;

&lt;p&gt;You'll need to install ODBC drivers on the machine where your DB server is. I actually didn't work on this part, it was made by the owner of the DB. But I'm pretty sure he did what's explained in this part : HFSQl Drivers on the server side.&lt;/p&gt;

&lt;p&gt;I've also found a vague note on the official website, &lt;a href="https://doc.pcsoft.fr/?2028086&amp;amp;name=parametres_des_bases_donnees#NOTE9_1" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;It doesn't matter if drivers aren't installed on your server, because we will explore a local solution for development. You can continue this tutorial anyway.&lt;/p&gt;




&lt;p&gt;Now we will only focus on the app side, where your php is runing, on &lt;strong&gt;Windows&lt;/strong&gt;.&lt;/p&gt;

&lt;h1&gt;
  
  
  Php on the app side
&lt;/h1&gt;

&lt;p&gt;You need Php installed, and this extension turned on :&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;pdo_odbc&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Locate you php.ini file :&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;;extension=pdo_odbc&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Remove the semicolon before, save file and restart Apache.&lt;/p&gt;

&lt;p&gt;Because we are on windows, you might be using WAMP stack, so, your file might be there :&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;C:\wamp64\bin\php\php8.0.15\php.ini&lt;/code&gt;  &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This extension will allow you to communicate with your DB via ODB, and request Db via PDO. But that's not all...&lt;/p&gt;

&lt;h1&gt;
  
  
  HFSQL drivers
&lt;/h1&gt;

&lt;p&gt;You also need some drivers, to tell ODBC how to communicate with this nudnik which is HFSQL. They are available on PC SOFT website.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Source : &lt;a href="https://pcsoft.fr/st/telec/modules-communs-26/wx26_101d.htm" rel="noopener noreferrer"&gt;https://pcsoft.fr/st/telec/modules-communs-26/wx26_101d.htm&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Scroll down and select &lt;strong&gt;ODBC26PACK101d.exe&lt;/strong&gt; to download HFSQL drivers for ODBC for &lt;strong&gt;Windows&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;They're as well available for Linux, but, after 2 days of try hard, with 2 different persons, on 2 different linux systems (both Debian based and up-to-date), we were only facing "&lt;code&gt;Segmentation fault&lt;/code&gt;" when trying to connect to any HFSQL DB from shell (not even from php). That's why this article will deal only with Windows platform.&lt;/p&gt;

&lt;p&gt;Once downloaded, just double click to launch the installer, and "next" each step, reading or not what is written.&lt;/p&gt;

&lt;h1&gt;
  
  
  Local HFSQL database
&lt;/h1&gt;

&lt;h2&gt;
  
  
  HFSQL server
&lt;/h2&gt;

&lt;p&gt;To test your installation, you can create a local DB by installing an HFSQL Server. This will help us to skip all the potential problems of remote authenticating / network / firewall. &lt;/p&gt;

&lt;p&gt;If you're sure about your connectivity and your credential, skip this part and just go to PDO via ODBC&lt;/p&gt;

&lt;p&gt;You can download HFSQL server application on the same webpage than the drivers :&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Source : &lt;a href="https://pcsoft.fr/st/telec/modules-communs-26/wx26_101d.htm" rel="noopener noreferrer"&gt;https://pcsoft.fr/st/telec/modules-communs-26/wx26_101d.htm&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Scroll down and select &lt;strong&gt;HFSQL26INSTALL101.exe&lt;/strong&gt; to download it.&lt;/p&gt;

&lt;p&gt;While you'll install it, you'll be asked to create a new DB on the fly. You'll have to chose a directory where your data will be saved, anywhere will fit. &lt;br&gt;
Check the server name and remove any blank space. &lt;br&gt;
Check the port : 4900 by default. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxpj4yv27uagxwq67m9tp.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxpj4yv27uagxwq67m9tp.JPG" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If it's your first HFSQL DB server on this computer, default name and port will be ok, if it's not, you'll have to change your port and server name to something else (eg. ComputerName_2 &amp;amp; 4901)&lt;/p&gt;

&lt;p&gt;Default username is "Admin" and there's no default password. You can set one if needed. Very well. Next.&lt;/p&gt;

&lt;p&gt;Skip the SMTP part.&lt;br&gt;
Skip the Active Directory part.&lt;br&gt;
Accept or not to participate to survey.&lt;br&gt;
Then the magic will happen.&lt;/p&gt;
&lt;h2&gt;
  
  
  HFSQL client
&lt;/h2&gt;

&lt;p&gt;While you installed the server, PC SOFT installed a client as well. It's called "Centre de contrôle", or "Control Center" in very good english. It's your PhpMyAdmin or MySQL Workbench-like software.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;It's located in : &lt;code&gt;C:\Program Files\PC SOFT\CC HFSQL&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Double-click &lt;code&gt;CC260HF64.exe&lt;/code&gt; file&lt;br&gt;
Check-in "New connection" and fill it up with &lt;code&gt;127.0.0.1&lt;/code&gt; or &lt;code&gt;localhost&lt;/code&gt;for the server address or name, the port, user and password, as set in the previous step, when you were installing the server.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3w5f0zz0sikfqg76fos6.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3w5f0zz0sikfqg76fos6.JPG" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You should connect locally to your server. If not, don't go further and check everything back.&lt;br&gt;
It should look like this :&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F631p0dpqrha2hgyvel33.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F631p0dpqrha2hgyvel33.png" alt="Screenshot connection"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can make a new DB by clicking "Nouvelle base de données" near the button to shutdown the server (Arrêter le serveur). Enter the name of your DB and validate.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fry5lz7tmzraxf8l3dfml.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fry5lz7tmzraxf8l3dfml.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It should look like that if you logged in your DB. &lt;/p&gt;

&lt;p&gt;I haven't been further into HFSQL by creating tables and inserting data here. I've just copy-past some files I got from the production server here :&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;C:\PC SOFT\Serveur HFSQL OrdinateurDeGael_2\BDD\devto-demo&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F52bu18siw9ku7cpxmmk8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F52bu18siw9ku7cpxmmk8.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Yep. That's all. &lt;code&gt;.FIC&lt;/code&gt; and &lt;code&gt;.NDX&lt;/code&gt; files dumped here and you got your DB. You can as well have directories into this directory, we will talk about this agony later.&lt;/p&gt;

&lt;p&gt;Now you have proven your ability to connect to your local HFSQL server with a dedicated software, you can try to do the same it with Php, via ODBC/PDO.&lt;/p&gt;
&lt;h1&gt;
  
  
  PDO via ODBC
&lt;/h1&gt;

&lt;p&gt;To connect to a HFSQL server you need a &lt;code&gt;DSN&lt;/code&gt;, also known as &lt;em&gt;Data Source Name&lt;/em&gt;. According to your version of the ODBC drivers, this long string can change. Reminder : we use version 26 of driver. And you should too.&lt;/p&gt;

&lt;p&gt;Into your php test file, type down :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$hf_dsn&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;sprintf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"odbc:DRIVER=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nv"&gt;HFSQL&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;;Server Name=%s;Server Port=%s;Database=%s;UID=%s;PWD=%s;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'127.0.0.1'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'4900'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'database_name'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'Admin'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;''&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Please note that &lt;strong&gt;&lt;code&gt;{HFSQL}&lt;/code&gt;&lt;/strong&gt; is necessary and might not be replaced by any other value. &lt;/p&gt;

&lt;p&gt;You can find on old forums, some of these values :&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;{Hyper File 7}, {HyperFileSQL} # WRONG&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;They're are &lt;strong&gt;not working&lt;/strong&gt; since version 26 (that we are using).&lt;/p&gt;

&lt;p&gt;For the rest : host, port, database name (that you might have created before), username (Admin is default on your local) and password (here I wrote no password).&lt;/p&gt;




&lt;p&gt;Now we got a complete DSN, we can try to connect via PDO :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$hf_hostname&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"127.0.0.1"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;$hf_port&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"4900"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;$hf_database&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"devto-demo"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;$hf_user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Admin"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;$hf_password&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;""&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nv"&gt;$hf_dsn&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;sprintf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"odbc:DRIVER=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nv"&gt;HFSQL&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;;Server Name=%s;Server Port=%s;Database=%s;UID=%s;PWD=%s;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$hf_hostname&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$hf_port&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$hf_database&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$hf_user&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$hf_password&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;$hf_dbh&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;PDO&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$hf_dsn&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$hf_user&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nv"&gt;$hf_password&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt; &lt;span class="no"&gt;PDO&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;ATTR_PERSISTENT&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;PDOException&lt;/span&gt; &lt;span class="nv"&gt;$ex&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
    &lt;span class="k"&gt;echo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$ex&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getMessage&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You will notice I've stored credential into variables, because they are passed twice : once in the DSN, and once in PDO. Dunno why. But it has to.&lt;/p&gt;

&lt;p&gt;If everything if fine, nothing will appear. If an error occurs, you messed up somewhere. The most common mistake I got was the wrong driver name &lt;code&gt;{HFSQL}&lt;/code&gt;, or the driver not installed (but we addressed these steps above). If it still not works, check login, password, server, port, a bit like with MySQL.&lt;/p&gt;

&lt;h1&gt;
  
  
  Queries, syntax and subtilities
&lt;/h1&gt;

&lt;h2&gt;
  
  
  Queries
&lt;/h2&gt;

&lt;p&gt;Now it's time to query your DB.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
 &lt;span class="nv"&gt;$query&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"SELECT * FROM [articles] WHERE (Author='JeanMatteo')"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
 &lt;span class="nv"&gt;$stmt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$hf_dbh&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;query&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$query&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; 
 &lt;span class="nv"&gt;$result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$stmt&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;fetchAll&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;PDO&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;FETCH_ASSOC&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
 &lt;span class="nb"&gt;var_dump&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$result&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;catch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;PDOException&lt;/span&gt; &lt;span class="nv"&gt;$ex&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
    &lt;span class="k"&gt;echo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$ex&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getMessage&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here's a simple request which get all the articles wrote by author named &lt;em&gt;JeanMatteo&lt;/em&gt; : table name is between &lt;strong&gt;square brackets&lt;/strong&gt; and the WHERE condition is between &lt;strong&gt;parentheses&lt;/strong&gt;.&lt;br&gt;
The rest of the code is common PDO code.&lt;/p&gt;
&lt;h2&gt;
  
  
  Diacritics
&lt;/h2&gt;

&lt;p&gt;Guess what ? You can put accents, or diacritics (like é, à, ù) in your tables NAME, and, ALSO in your cols name. What a pleasure to request a french 🥖 database.&lt;/p&gt;
&lt;h3&gt;
  
  
  Column name
&lt;/h3&gt;

&lt;p&gt;Imagine that our table &lt;code&gt;articles&lt;/code&gt; has a column named &lt;code&gt;Libellé&lt;/code&gt;, which  means "Label" in english. Character encoding will make some mess, and will return some �. So, how to access our column ?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;With array index.&lt;/strong&gt; First of all, fetch all data in &lt;code&gt;FETCH_BOTH&lt;/code&gt; mode :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="c1"&gt;// ...&lt;/span&gt;
&lt;span class="nv"&gt;$result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$stmt&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;fetchAll&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;PDO&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;FETCH_BOTH&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="c1"&gt;// ...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;this will returns an array both with numerical and associative indexes :&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fity8tlw9mkylji4ijp5h.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fity8tlw9mkylji4ijp5h.png" alt="Associative and numerical indexes"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now you can access to your &lt;code&gt;Libell�&lt;/code&gt; attribute like this :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt; &lt;span class="nv"&gt;$article&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s1"&gt;'2'&lt;/span&gt;&lt;span class="p"&gt;};&lt;/span&gt; &lt;span class="c1"&gt;//   $article-&amp;gt;Libellé won't work because of the DB encoding ;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you see, DB encoding isn't matching the one of our app. I couldn't set the DB connection encoding to utf-8, and I didn't want to change all my php app encoding to something else.&lt;/p&gt;

&lt;h3&gt;
  
  
  Table name + column name containing diacritics
&lt;/h3&gt;

&lt;p&gt;Imagine a table named &lt;code&gt;Détails&lt;/code&gt;. With a column named &lt;code&gt;IDDétail&lt;/code&gt;?&lt;br&gt;
How to query it ?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$query&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'SELECT * FROM ['&lt;/span&gt;&lt;span class="nb"&gt;utf8_decode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Détail).'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="nf"&gt;WHERE&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'.utf8_decode('&lt;/span&gt;&lt;span class="nc"&gt;IDDétail&lt;/span&gt;&lt;span class="s1"&gt;').'&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;69&lt;/span&gt;&lt;span class="s1"&gt;') '&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;utf8_decode&lt;/code&gt; will be your friend.&lt;/p&gt;

&lt;h2&gt;
  
  
  Subdirectory (nesting)
&lt;/h2&gt;

&lt;p&gt;As told previously, you can have directories into your DB directory. They can be used to differenciate deptartments, or companies. In HFSQL language, it's easy to access a subdirectory via backslash :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;  &lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;CompanyA&lt;/span&gt;&lt;span class="err"&gt;\&lt;/span&gt;&lt;span class="n"&gt;articles&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Author&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'JeanMatteo'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;in PHP you will replace the backslash with an underscore :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt; &lt;span class="nv"&gt;$query&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"SELECT * FROM [CompanyA_articles] WHERE (Author='JeanMatteo')"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Slowness
&lt;/h1&gt;

&lt;p&gt;If you access a big database, with a lot of tables and a lot of columns in each, with subdirectories and all, you will probably face delay issues.&lt;/p&gt;

&lt;p&gt;This is because HFSQL engine sends the totality of the tables name, structure, plus, (IMO) indexes. Because of this stunning behavior, I could see transiting between my Apache and the HFSQL remote server, around 10mb/s of data for 2 or 3 minutes, before the website shows up. It's totaly useless for a web usage.&lt;/p&gt;

&lt;p&gt;If your DB isn't that huge but connection is still slow, you can specify a parameter to your PDO connection method :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$hf_dbh&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;PDO&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$hf_dsn&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$hf_user&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nv"&gt;$hf_password&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
       &lt;span class="no"&gt;PDO&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;ATTR_PERSISTENT&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
&lt;span class="p"&gt;]);&lt;/span&gt; 

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;PDO::ATTR_PERSISTENT =&amp;gt; true&lt;/code&gt; &lt;strong&gt;in the constructor&lt;/strong&gt; won't close the HFSQL connection at the end of the script, as it usualy do.&lt;/p&gt;

&lt;p&gt;Then the visitor won't have to reconnect at every page he loads in its browser. It means the first page loading will still be slow, but not the next ones. It will be almost instant.&lt;/p&gt;

&lt;p&gt;The connection will be closed after a certain amount of time, but I couldn't find out how much, and how to set it (no documentation, no parameter).&lt;/p&gt;

&lt;p&gt;But if your DB is way to huge, you wont have any other solution to make another 'lite' database, containing only the few tables you are using, and syncing them with the original DB sometimes. That's how we proceed in our project.&lt;/p&gt;

&lt;p&gt;Good luck !&lt;/p&gt;

</description>
      <category>hfsql</category>
      <category>pdo</category>
      <category>php</category>
      <category>odbc</category>
    </item>
  </channel>
</rss>
