Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using PHP to connect to ServiceNow using ODBC

Status
Not open for further replies.

Malbordio

Programmer
Oct 19, 2014
12
PT
I have access to ServiceNow via ODBC. Driver is installed since ages, I've been running queries and getting results since ages.

I have PHP installed on my server and I want to use it to connect via odbc to ServiceNow.

I've tried many things, including php scripts like the one below:

PHP:
<?php
#DSN "mydb" with a user and password 
$connect = odbc_connect("ServiceNow", "myusername", "mypassword");

# query the users table for name and surname
$query = "SELECT * FROM incident";

# perform the query
$result = odbc_exec($connect, $query);

# fetch the data from the database
while(odbc_fetch_row($result)){
        $name = odbc_result($result, 2);
        print("$name\n");
}

# close the connection
odbc_close($connect);
?>

I'm getting the following warnings:


Code:
Warning: odbc_connect(): in C:\xampp\htdocs\odbc.php on line 3

Warning: odbc_exec() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\odbc.php on line 9

Warning: odbc_fetch_row() expects parameter 1 to be resource, null given in C:\xampp\htdocs\odbc.php on line 12

Warning: odbc_close() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\odbc.php on line 18

I'm using DataDirect OpenAccess SDK Local ODBC Driver and below are my current ODBC settings for ServiceNow:

Code:
Data Source Name: ServiceNow
Description: ServiceNow
Service Name: ServiceNow_ODBC
Service Data Source: ServiceNow
Custom Properties: url=https://servicenowserver.service-now.com

Any help and any clue on how to solve this is very much appreciated.
Thanks.

 
assuming you are using windows, set up a system dsn for the servicenow connection. then use odbc within php to connect to the system dsn.

typically system dsn do not require use of a pwd/username from within php but the user under whose credentials php is running should be the user with access to the system dsn. so if the dsn is already system, remove username and pwd and try again.
 
I have already a system dns configured in windows.
I've tried to setup the script to connect to odbc without the user and password, but yet I still get the same errors
 
if it is a system dsn (not user and not file) then i'm not sure what the issue is.

there is sometimes an error associated.

Code:
$connect = odbc_connect("ServiceNow");
if($connect === false) die(odbc_errormsg());
//
 
I've cut it to the basic and added your code.

It's now like this:

<?php
$connect = odbc_connect("ServiceNow");
if($connect === false) die(odbc_errormsg());
//

# close the connection
odbc_close($connect);
?>

And now I am getting:


Warning: odbc_connect() expects at least 3 parameters, 1 given in C:\xampp\htdocs\odbc.php on line 2

Warning: odbc_close() expects parameter 1 to be resource, null given in C:\xampp\htdocs\odbc.php on line 7

Any ideas?
 
fill the other two params with null

Code:
$connect = odbc_connect('ServiceNow', null, null);
...
 
Hum... ok, now I got something different:

Warning: odbc_connect(): in C:\xampp\htdocs\odbc2.php on line 2
[Microsoft][ODBC Driver Manager] The specified DSN contains an architecture mismatch between the Driver and Application

I use windows 8 64x, but so is the driver version!
 
I think I found what the issue was. At least I think I am now connected, it's not giving me the connect error as before. Somehow it is needed the 32bit version of the driver. So I've installed it and looks like it works. I will make sure this is really working. Be right back.
 
Ah yes. That old chestnut. You can fix it by using the 32bit version of the odbc snapin rather than the generally available version.
It is in the system folder from memory.



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top