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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ODBC in PHP to connect to ServiceNow

Status
Not open for further replies.

Malbordio

Programmer
Oct 19, 2014
12
0
0
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.

 
Since odbc_connect returns [tt]false[/tt] on error, and you do not test the returned value, it is not surprising that subsequent statements are not happy with [tt]false[/tt] as a resource. So, my guess is that your connection is failing.

Tom Morrison
Hill Country Software
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top