0

I am trying to make a localhosted WordPress site use the ODBC connections I use for business analytics.

I made a plugin and am trying to reference the functions in shortcode (because this is the only way I know to do this).

Below is my code:

$dsn = '****';
$user = '****';
$pw = '****';
$connect = odbc_connect($dsn, $user, $pw);
if ($connect == true){
    echo '<br> connected <br>';
} else{
    echo '<br> not connected <br>';
}

From what I understand this should be testing to see if the connection is open and it gives me an error (posted below). My big question is if I need to install an ODBC driver on the site to make it able to perform the connection.

If so, where do I find this?

I use four MS SQL servers on the domain and would also like to be able to work with access and excel.

Fatal error: Uncaught Error: Call to undefined function odbc_connect() in C:\Bitnami\wordpress-4.5.3-1\apps\wordpress\htdocs\wp-content\plugins\HPM-custom\HPM.php:54

Stack trace: 
#0 C:\Bitnami\wordpress-4.5.3-1\apps\wordpress\htdocs\wp-includes\shortcodes.php(326):HPM_API_E2('', '', 'HPM_API_E2')     
#1 [internal function]: do_shortcode_tag(Array) 
#2 C:\Bitnami\wordpress-4.5.3-1\apps\wordpress\htdocs\wp-includes\shortcodes.php(223):preg_replace_callback('/\\[(\\[?)(HPM_AP...','do_shortcode_ta...','[HPM_API_E2]\n[H...') 
#3 C:\Bitnami\wordpress-4.5.3-1\apps\wordpress\htdocs\wp-includes\plugin.php(235):do_shortcode('[HPM_API_E2]\n[H...') 
#4 C:\Bitnami\wordpress-4.5.3-1\apps\wordpress\htdocs\wp-includes\post-template.php(240):apply_filters('the_content', '[HPM_API_E2]\n[H...') 
#5 C:\Bitnami\wordpress-4.5.3-1\apps\wordpress\htdocs\wp-content\themes\generatepress\content-page.php(24):the_content() 
#6 C:\Bitnami\wordpress-4.5.3-1\apps\wordpress\htdocs\wp-includes\template.php(574):require('C:\\Bitnami\\word...') 
#7 C:\Bitnam in C:\Bitnami\wordpress-4.5.3-1\apps\wordpress\htdocs\wp-content\plugins\HPM-custom\HPM.php on line 54
S3S
  • 24,809
  • 5
  • 26
  • 45
pharman
  • 3
  • 1
  • 3

1 Answers1

0

$connect will never be true. This is because odbc_connect() does not return a boolean when it succeeds. It returns a connection IDinstead.

If the connection fails it will return an error or false, so it will end up in the else. If it succeeds it contains an ID and should evaluate to true.

if ($connect){
  echo '<br> connected <br>';
} else{
  echo '<br> not connected <br>';
}

Edit:

You've just added the error message you're getting. That error means the function is not available, and that will most likely be caused by the missing ODBC drivers for your php client. Someone else made this post on how to install this:

Call to undefined function odbc_connect() message while connecting SAP Hana database

I hope this helps.

Community
  • 1
  • 1
Kevinvhengst
  • 1,672
  • 4
  • 27
  • 40