Fedora Linux Support Community & Resources Center

Go Back   FedoraForum.org > Fedora 17/18 > Using Fedora
FedoraForum Search

Forgot Password? Join Us!

Using Fedora General support for current versions. Ask questions about Fedora and it's software that do not belong in any other forum.

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 2nd November 2008, 04:22 PM
Frustant Offline
Registered User
 
Join Date: Nov 2008
Posts: 4
PHP code won't connect into MySQL database through ODBC DSN

Hi there

I have Fedora 9, MySQL 5, PHP 5, and the standard ODBC tools installed.

I have configured my odbc.ini file, in /etc/, to hold the details for my database, and others, and am able to connect into the database through either Open Office or ISQL and query the data.

However, using the following PHP script, see below, I get no result at all (in fact I am only presented with the result of the first echo). I have search this but am struggling to find anything to resolve it.

I have to use ODBC as my live website does and so I want to develop in the same environment. Can you help me?

Thanks

<?php

error_reporting(E_ALL);

echo "Begining - Setting up connection <br />";
# connect to a DSN "DSN_NAME" with a user "Bob" and password "Marley"
$connect = odbc_connect("test", "test", "test") or die(mysqlerror());
echo "Connection set, now setting query <br />";
# query the users table for all fields
$query = "SELECT * FROM master";
echo "Query set, now executing <br />";
# perform the query
$result = odbc_exec($connect, $query);
echo "Execution complete, now printing results <br />";
# fetch the data from the database
while(odbc_fetch_row($result)) {
$field1 = odbc_result($result, 1);
$field2 = odbc_result($result, 2);
print("$field1 $field2\n");
}

# close the connection
odbc_close($connect);

?>
Reply With Quote
  #2  
Old 2nd November 2008, 06:04 PM
Frustant Offline
Registered User
 
Join Date: Nov 2008
Posts: 4
Hi all, an update. Going back to basics on my searching has lead me to discover, and install, php-odbc. This improves my situation, now I am battling with SELinux constraints. Further update soon.
Reply With Quote
  #3  
Old 2nd November 2008, 06:14 PM
Frustant Offline
Registered User
 
Join Date: Nov 2008
Posts: 4
All working, for the moment. Please ignore. For others who have a similar problem, ensure you have php-odbc (yum install php-odbc) installed before progressing.

Thanks, you may hear more from me :-)
Reply With Quote
  #4  
Old 2nd November 2008, 10:46 PM
Zotter's Avatar
Zotter Offline
Registered User
 
Join Date: May 2004
Location: Central Wyoming
Posts: 637
Are you running on a Windows machine <g>? Maybe you need to offer connectivity via an ODBC client of some kind - I dunno. But on the half dozen or so LAMP machines I've got, none of them have any ODBC stuff, of any kind.

ODBC isn't normally used - special when PHP and MySQL are on the same machine.

Just install php-mysql (yum install php-mysql) and go to town.

PHP connecs to MySQL via Unix socket - not ODBC - normally.
__________________
If it ain't broken - you're not really trying....
Registered Linux user #227845
Reply With Quote
  #5  
Old 3rd November 2008, 03:50 PM
Frustant Offline
Registered User
 
Join Date: Nov 2008
Posts: 4
Hey Zotter

Fedora 9 is my OS, you are quite right re PHP and MySQL not needing ODBC. This is how I initially developed the website, however the live site IS hosted on Windows and so uses ODBC to connect into MySQL and hence I had to install php-odbc to get it to work on my dev machine.

All is fine now though.
Reply With Quote
Reply

Tags
code, connect, database, dsn, mysql, odbc, php

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to connect to mysql database in linux with C linuxpcmancn Programming & Packaging 3 25th December 2007 07:25 AM
Use ODBC from XP to Fedora MySQL EddieG Servers & Networking 1 19th June 2005 05:52 PM
Browser can't connect MySQL database Artemis Servers & Networking 10 13th April 2005 07:27 PM
Connect database mysql by QTdedign??? multsyh Programming & Packaging 1 11th June 2004 04:28 PM


Current GMT-time: 17:37 (Tuesday, 21-05-2013)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat