ODBC connection on a wordpress site - wordpress

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

$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.

Related

Not able to connect Firebase with php

I am using firebase as backend in php, but when i am calling "fromJsonFile" method of "ServiceAccount" i am getting bellow error:
Fatal error: Uncaught Error: Call to private method
Kreait\Firebase\ServiceAccount::fromJsonFile() from context '' in
C:\xampp\htdocs\wordpress\wp-content\plugins\firebase-connection.php:7
Stack trace: #0 C:\xampp\htdocs\wordpress\wp-content\plugins\sb-api\sb_api.php(31):
include() #1 C:\xampp\htdocs\wordpress\wp-settings.php(362):
include_once('C:\xampp\htdocs...') #2
C:\xampp\htdocs\wordpress\wp-config.php(90):
require_once('C:\xampp\htdocs...') #3
C:\xampp\htdocs\wordpress\wp-load.php(37):
require_once('C:\xampp\htdocs...') #4
C:\xampp\htdocs\wordpress\wp-admin\admin.php(34):
require_once('C:\xampp\htdocs...') #5
C:\xampp\htdocs\wordpress\wp-admin\index.php(10):
require_once('C:\xampp\htdocs...') #6 {main}
thrown in C:\xampp\htdocs\wordpress\wp-content\plugins\firebase-connection.php
on line 7
The site is experiencing technical difficulties. Please check your site admin email inbox for instructions.
Here is my code:
<?php
require __DIR__.'/vendor/autoload.php';
use Kreait\Firebase\Factory;
use Kreait\Firebase\ServiceAccount;
$serviceAccount = ServiceAccount::fromJsonFile(__DIR__.'/google-service-account.json');
$firebase = (new Factory)
->withServiceAccount($serviceAccount)
->create();
$database = $firebase->getDatabase();
?>
Can you tell us the version of the firebase-php that you are currently using?
If you are using version lower than 5.x please update to the latest version.
https://github.com/kreait/firebase-php
It is using php 7.2^. Current wordpress requires 7.3 so it must be updated to latest version
Here is the documentation as well.
https://firebase-php.readthedocs.io/en/latest/
I don't know exactly what the problem is but it seems the error says you can't access a private method, so you should access it by updating it to public or public static method.
For ver 5.x
// #see https://firebase-php.readthedocs.io/en/5.2.0/troubleshooting.html
$factory = (new Factory)->withServiceAccount(__DIR__.'/google-service-account.json');
$database = $factory->createDatabase();
// if you want auth
//$auth = $factory->createAuth();

How to create a VM with multiple NICs with Terraform on Openstack

I try to use Terraform to deploy some machines on an Openstack Cloud.
I have no problem to create networks, subnet, keys, security groups and rules, floating ip, network ports (with security groups attached), but, when I try to create compute instances with two NICs (network ports created before), I have a syntax error with no hint to resolve it.
Could you help me please ?
My code is:
resource "openstack_compute_instance_v2" "RNGPR-REBOND-01" {
name = "RNGPR-REBOND-01"
flavor_name = "${var.MyFlavor}"
image_id = "${var.MyImage}"
key_pair = "${var.CODOB}-keypair"
network {
port = "${openstack_networking_port_v2.RNGPR-REBOND-01-eth0.id}"
access_network = true
}
network {
port = "${openstack_networking_port_v2.RNGPR-REBOND-01-eth1.id}"
}
floating_ip = "${openstack_compute_floatingip_v2.FloatingIp-RNGPR-REBOND-01.address}"
}
resource "openstack_compute_instance_v2" "RNGPR-LB-01" {
name = "RNGPR-LB-01"
flavor_name = "${var.MyFlavor}"
image_id = "${var.MyImage}"
key_pair = "${var.CODOB}-keypair"
network {
port = "${openstack_networking_port_v2.RNGPR-LB-01-eth0.id}"
}
network {
port = "${openstack_networking_port_v2.RNGPR-LB-01-eth1.id}"
}
floating_ip = "${openstack_compute_floatingip_v2.FloatingIp-RNGPR-LB-01.address}"
}
And the syntax error is:
Error applying plan:
2 error(s) occurred:
* openstack_compute_instance_v2.RNGPR-REBOND-01: Error creating OpenStack server: Invalid request due to incorrect syntax or missing required parameters.
* openstack_compute_instance_v2.RNGPR-LB-01: Error creating OpenStack server: Invalid request due to incorrect syntax or missing required parameters.
.
From my experience, these error messages aren't very helpful.
I would first set TF_LOG=DEBUG and OS_DEBUG=1 wherever you are running terraform. This will print error messages that are actually beneficial.
One time I was trying to create a server with a key pair that my user didn't have access to in openstack. I was receiving the same error and didn't figure it out until Debugging was set.

sqlite jdbc error SQLITE_IOERR_LOCK

I have a runnable jar for a java8 program which uses sqlite-jdbc 3.14.2. It works fine on windows 10 and ubuntu. i.e. i can query stuff on these platforms on all the tables. However, when i run it on FreeBSD 10.3-releasep4, it gives me the following error when i run queries on all the tables.
[SQLITE_IOERR_LOCK] I/O error in the advisory file locking logic (disk I/O error) on FreeBSD 10.3-release
Please advise a workaround or solution.
Same issue exists with 3.16.1
So I finally found out what was wrong. It was an NFS mounted volume that was causing the problem. With DB file on local file system, it works like a charm.
If anyone is coming to this question at later time, this error can be reproduced by first creating or opening a DB with WAL journalling mode, writing something, then closing the DB and trying to open it again in read-only mode with journalling off. This unit test will reproduce the error:
#Test
public void mixJournalingModesFailureTest()
{
File tempDb = File.createTempFile("tempdbtest", ".db");
tempDb.deleteOnExit();
// Open a temp DB in RW mode with WAL journalling
String url = "jdbc:sqlite:" + tempDb.getAbsolutePath();
SQLiteConfig config = new SQLiteConfig();
// Ser read-write with WAL journalling
config.setJournalMode( SQLiteConfig.JournalMode.WAL );
config.setReadOnly( false );
Properties props = config.toProperties();
Connection conn = DriverManager.getConnection( url, props );
// Write something
try ( Statement statement = conn.createStatement() )
{
statement.execute( "CREATE TABLE test (words text)" );
}
// Close the DB
conn.close();
// Open the DB again but with journalling off and in read-only mode
config.setJournalMode( SQLiteConfig.JournalMode.OFF );
config.setReadOnly( true );
props = config.toProperties();
try
{
// This will throw the SQLITE_IOERR_LOCK advisory lock exception
DriverManager.getConnection( url, props );
fail( "Should throw advisory lock exception" );
}
catch ( SQLException ignore ) {}
}

RJython send Mail via .bat Firewall

We have .bat Files which call an R-script and generate some data and then send an email to certain users via rJython.
If I run this script in RStudio everything goes well and the mail is sent. But if i call the .bat file we get the following error.
It has probably something to do with the firewall in our company, can somebody help us out? We need to tell our IT departement something bc they cant help us either.
Error in jython.exec(rJython,mail): (-1, 'Unmapped exception:java.net.SocketException: Permission denied: connect') Execution halted
The R-Code to send the mail is:
#Sendmail Code
rJython<-rJython()
rJython$exec("import smtplib")
rJython$exec("from email.MIMEText import MIMEText")
rJython$exec("import email.utils")
rJython$exec("COMMASPACE = ', '")
recipients_string_j = paste("toaddrs = [",recipients_string,"]",sep="")
#mail config
mail<-c( fromaddr = 'test#XXX.com",
recipients_string_j,
paste("msg = MIMEText('",data.frame,"','html')",sep="",collapse=""),
paste("msg['Subject'] = 'DUMMY SUBJECT'"),
"msg['From'] = fromaddr",
"msg['To']= COMMASPACE.join(toaddrs)",
"server = smtplib.SMTP('00.00.00.000')",
"server.sendmail(fromaddr, toaddrs, msg.as_string())",
"server.quit()")
#send mail
jython.exec(rJython,mail)

SQLAllocConnect success,but SQLConnect fail

I had made connector/ODBC successfully,then I write some code:
SQLHENV henv;
SQLHDBC phdbc;
SQLRETURN retcode;
retcode = SQLAllocEnv(&henv);
retcode = SQLAllocConnect(henv,&phdbc);
if(retcode == SQL_SUCCESS)
{
char *a="cc_mysql";
char *b="chen1991";
retcode = SQLConnect(phdbc,(SQLCHAR*)a,SQL_NTS,(SQLCHAR*)b,SQL_NTS,(SQLCHAR*)b,SQL_NTS);
}
but I failed to connect. I debug it and found that the SQLAllocConnect return true ,but SQLConnect return -1,I can't understand what happened.
What happened is your call to SQLConnect failed and you need to call SQLError to get the error back. I'd just be guessing but may be the DSN cc_mysql does not exist or your username/password are invalid, or mysql does not allow that user to access it etc.
BTW, you should really be writing at least ODBC 3 applications these days and to do that you should be calling SQLAllocHandle, SQLSetEnvAttr (to set ODBC behavior), SQLDriverConnect and SQLGetDiagRec.

Resources