Koozali.org formerly Contribs.org

Adding extension to PHP - ODBC/MSSQL connection

Adding extension to PHP - ODBC/MSSQL connection
« on: April 20, 2021, 09:32:00 AM »
Hi,

I used php odbc / FreeTDS quite a bit in sme 9 and now trying to configure SME 10 so I can upgrade. I pull a little information from a MSSQL database and need to get a connection. After installing php-odbc and unixODBC as well as FreeTDS I have had no luck.

Currently getting "Call to undefined function odbc_connect()". Could someone point me in the right direction on how to add extensions correctly using the SME10 php-fpm setup?

Thanks,
« Last Edit: April 20, 2021, 10:19:55 AM by Bozely »

Re: Adding extension to PHP - ODBC/MSSQL connection
« Reply #1 on: April 20, 2021, 10:18:46 AM »
Managed to connect to the database via isql but php doesn't seem to see odbc
« Last Edit: April 20, 2021, 10:22:12 AM by Bozely »

Offline Jean-Philippe Pialasse

  • *
  • 1,878
  • aka Unnilennium
    • http://smeserver.pialasse.com
Re: Adding extension to PHP - ODBC/MSSQL connection
« Reply #2 on: April 20, 2021, 01:04:22 PM »
Code: [Select]
yum install php*-php-odbc
if still not working you might need a templates-custom to enabled it against non php5 version according google

Re: Adding extension to PHP - ODBC/MSSQL connection
« Reply #3 on: July 14, 2021, 03:17:02 PM »
Code: [Select]
yum install php*-php-odbc
if still not working you might need a templates-custom to enabled it against non php5 version according google

I have the same issue with SME 10.0, it appears that odbc is not loading. Added complication is that the command to restart Apache before 10.0 was /etc/init.d/httpd-e-smith restart. After each adjustment to php.ini to debug the issue, I have to reboot the server, very dull! Maybe this is a bug?
All's well that ends.

Offline ReetP

  • *
  • 2,974
Re: Adding extension to PHP - ODBC/MSSQL connection
« Reply #4 on: July 14, 2021, 08:43:40 PM »
For clues look at the events in:

Code: [Select]
/etc/e-smith/events

Try

Code: [Select]
signal-event smeserver-php-update
Or possibly

Code: [Select]
signal-event webapps-update
...
1. Read the Manual
2. Read the Wiki
3. Don't ask for support on Unsupported versions of software
4. I have a job, wife, and kids and do this in my spare time. If you want something fixed, please help.

Bugs are easier than you think: http://wiki.contribs.org/Bugzilla_Help

If you love SME and don't want to lose it, join in: http://wiki.contribs.org/Koozali_Foundation

Offline TerryF

  • grumpy old man
  • *
  • 1,532
Re: Adding extension to PHP - ODBC/MSSQL connection
« Reply #5 on: July 14, 2021, 09:59:48 PM »
Added complication is that the command to restart Apache before 10.0 was /etc/init.d/httpd-e-smith restart. After each adjustment to php.ini to debug the issue, I have to reboot the server, very dull! Maybe this is a bug?

# systemctl restart httpd-e-smith.service
--
qui scribit bis legit

Offline ReetP

  • *
  • 2,974
Re: Adding extension to PHP - ODBC/MSSQL connection
« Reply #6 on: July 14, 2021, 10:27:56 PM »
The events *should* expand the templates, and restart the services.

Terrys command will just restart the web server.

Just depends what you require.
...
1. Read the Manual
2. Read the Wiki
3. Don't ask for support on Unsupported versions of software
4. I have a job, wife, and kids and do this in my spare time. If you want something fixed, please help.

Bugs are easier than you think: http://wiki.contribs.org/Bugzilla_Help

If you love SME and don't want to lose it, join in: http://wiki.contribs.org/Koozali_Foundation

Re: Adding extension to PHP - ODBC/MSSQL connection
« Reply #7 on: July 15, 2021, 09:23:24 AM »
It's probably worth ensuring your ibay php version in the server manager matches the php-odbc version you're installing. This was my issue.

Code: [Select]
yum install php74-php-odbc
I was working off a clean install and didn't need to make any additional changes to get this working. Are you using this in conjuction with FreeTDS?
« Last Edit: July 15, 2021, 09:25:52 AM by Bozely »

Re: Adding extension to PHP - ODBC/MSSQL connection
« Reply #8 on: July 15, 2021, 10:03:25 AM »
It's probably worth ensuring your ibay php version in the server manager matches the php-odbc version you're installing. This was my issue.

Code: [Select]
yum install php74-php-odbc
I was working off a clean install and didn't need to make any additional changes to get this working. Are you using this in conjuction with FreeTDS?

Thanks to all for chipping in.
Yes, FreeTDC to an MS SQL server.
The php74-php-odbc was probably the sticking point and I imagine that would have been covered in php*-php-odb suggested by Jean-Philippe earlier.

Having done the above, I've now progressed to Data source not found on odbc_connect.
On SME 9.2, the data source was specified in /etc/odbc.ini
For some reason that I've yet to discover, in 10.0 this doesn't appear to map over.
All the usual test using tsql etc works as expected. If I figure it before any one else shines a light on what I've overlooked, I'll post back here with the solution.

Terry.  systemctl restart httpd-e-smith.service, I think was the answer I was after, allowing me to experiment with
odbc.ini. My procedures are behind on this one, as are the Wiki documents.
All's well that ends.

Offline TerryF

  • grumpy old man
  • *
  • 1,532
Re: Adding extension to PHP - ODBC/MSSQL connection
« Reply #9 on: July 15, 2021, 11:27:46 AM »
mate you and those who spend the time chasing things down rabbit holes do us all a favour :-)
--
qui scribit bis legit

Re: Adding extension to PHP - ODBC/MSSQL connection
« Reply #10 on: July 15, 2021, 11:39:23 AM »
Make sure you can succesfully ping the target machine by the computer name. I had to add an entry into my host file to get this working.

Offline TerryF

  • grumpy old man
  • *
  • 1,532
Re: Adding extension to PHP - ODBC/MSSQL connection
« Reply #11 on: July 16, 2021, 02:00:40 AM »
Terry.  systemctl restart httpd-e-smith.service, I think was the answer I was after, allowing me to experiment with
odbc.ini. My procedures are behind on this one, as are the Wiki documents.

Hopefully helps others - https://wiki.koozali.org/Useful_Commands#Restart_httpd
and
https://wiki.koozali.org/Services#SME10
--
qui scribit bis legit

Offline Jean-Philippe Pialasse

  • *
  • 1,878
  • aka Unnilennium
    • http://smeserver.pialasse.com
Re: Adding extension to PHP - ODBC/MSSQL connection
« Reply #12 on: July 16, 2021, 05:41:16 AM »
/etc/odbc.ini :

have you search the internet for the correct path in case you use php74 software collection ?

Re: Adding extension to PHP - ODBC/MSSQL connection
« Reply #13 on: September 03, 2021, 11:34:28 AM »
/etc/odbc.ini :

have you search the internet for the correct path in case you use php74 software collection ?

Well, it's been months finding time to get SME 10 on the road, and for what it's worth, I'll share my findings, regarding
odbc_connect and PHP 7.4 on this platform.

In SME9, PHP 5.4 I'd specified the dsn (first parameter of odbc_connect()) as "ProductDB" which in turn was specified in /ect/odbc.ini
Moving on to SME 10, this appears to no longer work, probably as a function of php7.4 (correct me any one if I'm wrong)
Postulating this to be the salient difference, the dsn must be now be passed in as an array, example

//    $Source = "ProductDB";
      $Source = "Driver=FreeTDS;Server=192.168.1.10;Port=1433;Database=SERVCO;TDS_Version=8.0;";
 
   // Begin Here
      $this->Connection = odbc_connect($Source,$Login, $Paswd, $this->Cursor) or die('Could not connect to the server!!');
      if(!isset($this->Connection)) die("Database connection failed");


I can conform that [FreeTDS] elected in the dsn needs to be specified in /etc/odbcint.ini
Mean while, if any one can drive a coach and horses through my findings please do so.


All's well that ends.