Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

PHP connecting to ODBC


  • Please log in to reply
8 replies to this topic

#1 KamakaZ

KamakaZ

  • Members
  • 739 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Victoria
  • Local time:11:14 AM

Posted 17 September 2009 - 02:14 AM

Hey,

Has anyone ever tried to use php to connect to an Advantage ODBC database on a remote server? Well the server with the database is in the same LAN i just need to open the port and from what i can tell add an extension to php.ini. I don't know what port or anything...

Brad

There's no place like 127.0.0.1
There are 10 types of people in the world, those that can read binary, and those who can't.


BC AdBot (Login to Remove)

 


#2 KamakaZ

KamakaZ
  • Topic Starter

  • Members
  • 739 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Victoria
  • Local time:11:14 AM

Posted 20 September 2009 - 10:33 PM

Does anyone know how to add the extension into php.ini for ODBC databases on a linux box?

There's no place like 127.0.0.1
There are 10 types of people in the world, those that can read binary, and those who can't.


#3 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:06:14 PM

Posted 20 September 2009 - 11:52 PM

You need to know what port, otherwise it will not work.

#4 KamakaZ

KamakaZ
  • Topic Starter

  • Members
  • 739 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Victoria
  • Local time:11:14 AM

Posted 21 September 2009 - 12:07 AM

i have contacted the software mob... they say the person that knows will return an email to me later this week...

in the mean time, how can i go about getting my webserver ready to interact with an odbc database?

I've been looking into ODBC connectors and what not, do i need these if i going to use php to make the connection?

There's no place like 127.0.0.1
There are 10 types of people in the world, those that can read binary, and those who can't.


#5 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:06:14 PM

Posted 21 September 2009 - 01:03 AM

in the mean time, how can i go about getting my webserver ready to interact with an odbc database?


Typically one would set up a test class to mimic connecting to a database. Meaning that one would set up a test database on their own server so that when one want s to connect to the real server, all they would need to do is change database info.

In order to connect to an Advantage db, you will need to add the proper PHP extensions. Other than that, there are tons of search results that deal with your issue. You will just have to comb through them to find what you need.

#6 KamakaZ

KamakaZ
  • Topic Starter

  • Members
  • 739 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Victoria
  • Local time:11:14 AM

Posted 22 September 2009 - 01:44 AM

I've managed to get it set up and can connect to the Data Source, just canít seem to get my head around how the odbc commands in php work.

This is the connection I have got (which works fine as the DSN is set up in windows, havenít been able to get it to work in linux yet)

<?
$conn = odbc_connect("GunnSrvModODBC", "", "");
$query = "SELECT * FROM DSTOCK LIMIT 0, 10";
?>


DSTOCK is a valid table and has data in it, whenever i try to call data from it it returns a blank page not matter what odbc_ function i try to use...

Can someone please help with this?

Cheers,

~Kam

There's no place like 127.0.0.1
There are 10 types of people in the world, those that can read binary, and those who can't.


#7 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:06:14 PM

Posted 22 September 2009 - 10:19 AM

You have a connection to the database, and you have a sql query that you want to send to the database; now you have to actually send the query to the database. Here is how I did it in a recent project. The type of database is different, but the process is the same:

[code=auto:0]
mysql_connect("localhost","puser", "val_puser") or die(mysql_error());
mysql_select_db("valiantvineyards") or die(my_sql_error());

#8 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:06:14 PM

Posted 22 September 2009 - 10:27 AM

You have a connection to the database, and you have a sql query that you want to send to the database; now you have to actually send the query to the database. Here is how I did it in a recent test project. The type of database is different, but the process is the same:

mysql_connect("localhost","user", "pass") or die(mysql_error());
	mysql_select_db("valiantvineyards") or die(my_sql_error());
	$result = mysql_query("SELECT id, name FROM headings");

	while($row = mysql_fetch_array($result)){
		$arr = array('id' => $row['id'], 'name' => $row['name']);
	}

The first line establishes a connection to the database. the second line establishes which table to use. The third line is the actual query that gets a result set. The while loop is used to get the records from the result set, one by one. You need to spend some time learning how SQL works, and understanding the odbc docs, or you are going to have a really tough time.

#9 KamakaZ

KamakaZ
  • Topic Starter

  • Members
  • 739 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Victoria
  • Local time:11:14 AM

Posted 22 September 2009 - 05:40 PM

i know how to do mysql_query 's but with an odbc database, well this is what i'm making of it, you have to prepare the query with odbc_prepare then you have to execute the prepared query with some parameters. Also unlike mySQL you don't have to select the database as this is all done with the ODBC connector.

There's no place like 127.0.0.1
There are 10 types of people in the world, those that can read binary, and those who can't.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users