BleepingComputer.com: PHP connecting to ODBC

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

PHP connecting to ODBC

#1 User is offline   KamakaZ 

  • Senior Member
  • PipPipPipPip
  • Find Topics
  • Group: Members
  • Posts: 557
  • Joined: 26-August 08
  • Gender:Male
  • Location:Victoria

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
If I am helping you and don't reply in 24 hours please send me a PM

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.

#2 User is offline   KamakaZ 

  • Senior Member
  • PipPipPipPip
  • Find Topics
  • Group: Members
  • Posts: 557
  • Joined: 26-August 08
  • Gender:Male
  • Location:Victoria

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?
If I am helping you and don't reply in 24 hours please send me a PM

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 User is offline   groovicus 

  • Hail Groovicus!
  • PipPipPipPipPipPip
  • Find Topics
  • Group: Moderator
  • Posts: 9,605
  • Joined: 05-June 04
  • Gender:Male
  • Location:Centerville, SD

Posted 20 September 2009 - 11:52 PM

You need to know what port, otherwise it will not work.
"Take the risk of thinking for yourself, much more happiness, truth, beauty, and wisdom will come to you that way" - Christopher Hitchens

#4 User is offline   KamakaZ 

  • Senior Member
  • PipPipPipPip
  • Find Topics
  • Group: Members
  • Posts: 557
  • Joined: 26-August 08
  • Gender:Male
  • Location:Victoria

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?
If I am helping you and don't reply in 24 hours please send me a PM

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 User is offline   groovicus 

  • Hail Groovicus!
  • PipPipPipPipPipPip
  • Find Topics
  • Group: Moderator
  • Posts: 9,605
  • Joined: 05-June 04
  • Gender:Male
  • Location:Centerville, SD

Posted 21 September 2009 - 01:03 AM

Quote

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.
"Take the risk of thinking for yourself, much more happiness, truth, beauty, and wisdom will come to you that way" - Christopher Hitchens

#6 User is offline   KamakaZ 

  • Senior Member
  • PipPipPipPip
  • Find Topics
  • Group: Members
  • Posts: 557
  • Joined: 26-August 08
  • Gender:Male
  • Location:Victoria

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
If I am helping you and don't reply in 24 hours please send me a PM

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 User is offline   groovicus 

  • Hail Groovicus!
  • PipPipPipPipPipPip
  • Find Topics
  • Group: Moderator
  • Posts: 9,605
  • Joined: 05-June 04
  • Gender:Male
  • Location:Centerville, SD

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]
mysql_connect("localhost","puser", "val_puser") or die(mysql_error());
mysql_select_db("valiantvineyards") or die(my_sql_error());
"Take the risk of thinking for yourself, much more happiness, truth, beauty, and wisdom will come to you that way" - Christopher Hitchens

#8 User is offline   groovicus 

  • Hail Groovicus!
  • PipPipPipPipPipPip
  • Find Topics
  • Group: Moderator
  • Posts: 9,605
  • Joined: 05-June 04
  • Gender:Male
  • Location:Centerville, SD

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.
"Take the risk of thinking for yourself, much more happiness, truth, beauty, and wisdom will come to you that way" - Christopher Hitchens

#9 User is offline   KamakaZ 

  • Senior Member
  • PipPipPipPip
  • Find Topics
  • Group: Members
  • Posts: 557
  • Joined: 26-August 08
  • Gender:Male
  • Location:Victoria

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.
If I am helping you and don't reply in 24 hours please send me a PM

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.

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users