Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2992
  • Last Modified:

Installing php with odbc on a Linux box

I'm a complete Windows junkie, and I think I'm making this process harder than it really is... Anyways, here goes:
I need to connect to a MSSQL server from a Linux box (Fedora Core 5) using PHP. I already installed freeTDS and configured a DSN, at least that's what I think I did, because I'm able to run a query from the command line using isql. This is the command that I use to do so:

isql -v MSSQLTestServer "user" "pass"

After running this command I immediately get a SQL> prompt.

Now my problem is accessing the MSSQL server using php... I read in the freeTDS user guide that I needed to configure PHP using ./configure --with-iodbc=/usr/local, but I got errors on each odbc command. I then changed the configuration to ./configure --with-unixodbc=/usr/local, I got no errors during the make and make install process, but I still can't connect. If I need to install something, please give me details, most of the web pages out there that give instructions are oriented to Linux users. I know nothing about rpms, yums, configure code, etc. I am reading though, I know there's a lot to learn with a new OS! This is the code that I'm using:

<?php
$connect = odbc_connect("MSSQLTestServer","user","pass");
if (!$connect) die ("Invalid connection");
?>

As you guessed it, everytime I open the page I get "Invalid connection". I appreciate any help. Thanks!
0
horalia
Asked:
horalia
  • 47
  • 20
  • 3
  • +2
1 Solution
 
horaliaAuthor Commented:
One more thing, the server is a PC, and I can reload Fedora Core 5 over and over again and erase any mess that I've done. I think I've already loaded it about 5 times....
0
 
Richard QuadlingSenior Software DeverloperCommented:
Try DSN-less connection.

This is the make connection method for my DB Class. objKrypt contains an encrypted password.

      private function MakeDBConnection($objKrypt)
            {
            $resResult = NULL;
// ****************************************
// Make a connection to the database server
// ****************************************
            $resResult = @odbc_pconnect("Driver={SQL Server};Server={$this->sServer};Database={$this->sDB}", $this->sUser, trim($objKrypt->sData));
            if ($resResult === False)
                  {
                  throw new class_DB_Exception(
                        class_DB_Exception::DB_ERROR_SERVER_CONNECT,
                        array(
                              $this->sServer
                              )
                        );
                  }
            return $resResult;
            }
0
 
hernst42Commented:
Accessing MS-SQLServer via freeTDS requires the mssql-extension see http://de3.php.net/mssql Thats the way I got connections to work with a SQL-Server, I never got iodbc to work.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
horaliaAuthor Commented:
hernst42, can you give me an example? Like I said at the beginning, I'm completely new to this, I've done a lot of reading but these past few days I feel like I've been running around in circles...I already have a Data Source name setup, MSSSQLTestServer. I have tried using the mssql functions before, but haven't had any luck yet. Do I have to configure PHP in order to do this?
0
 
horaliaAuthor Commented:
This is how my code looks, nothing happened:
<?php
$msconnect = mssql_connect("10.7.122.28:1433","user","pass");
$msdb = mssql_select_db("ProdDB",$connect);
$msquery = "select * from dbo.RPT_Customer";
$msresults = mssql_query($msquery);
while ($row = mssql_fetch_array($msresults))
{
  echo "<li>" . $row['Customer_ID'] . " " . $row['Customer_Name'] . "</li>\n";
}
?>
I also confured php for the 1000th time using the --with-mssql command. This time, I got the following statement at the end:

checking for MSSQL support via FreeTDS... yes
configure: error: Cannot find FreeTDS in known installation directories. I guess I'll have to install freeTDS again.... this is driving me nuts! :-(
0
 
hernst42Commented:
Can you give me a little more information how you set up the FreeTDS compiled by your own (configure command you used?), rpm, deb  and which php-source you try to compile.

Do you use FC5 on a 64bit System?
0
 
horaliaAuthor Commented:
I installed FreeTDS with the help of another Expert. These are his instructions:

*****************************************************************
Ok let's try this:

# rpm --import http://dries.studentenweb.org/rpm/RPM-GPG-KEY.dries.txt

create the file in /etc/yum.repos.d/dries.repo with the following contents:
[dries]
name=Extra Fedora rpms dries - $releasever - $basearch
baseurl=http://ftp.belnet.be/packages/dries.ulyssis.org/fedora/linux/$releasever/$basearch/dries/RPMS/
enabled=1
gpgcheck=1

Then issue the command:

# yum install freetds
******************************************************************************

I then followed the instructions on how to set up the ODBC detailed on the unixODBC site. This is what I did:

1. Followed instructions to install freeTDS described earlier
2. Verified that freeTDS was working with the MSSQL that I wanted to connect to using the following command at root:
#tsql -S <ip address of MSSQL server> -U <password>
3. Created a file under root named tds.driver.template with the following lines:
[FreeTDS]
Description = v0.63 with protocol v8.0
Driver = /usr/lib/libtdsodbc.so.0
4. Executed the following command, which registers the ODBC driver:
#odbcinst -i -d -f tds.driver.template
5. Created a second file also under root named tds.datasource.template with the following lines:
[MSSQLTestServer]
Driver = FreeTDS
Description = <DB Description>
Trace = No
Server = <MSSQL ip address>
Port = 1433
Database = <DB name>
6. Executed the following command, which creates the ODBC data source:
# odbcinst -i -s -f tds.datasource.template -l
7. Restarted the server with the following command:
#service httpd restart
8. Connected to the server using the following command:
#isql -v MSSQLTestServer <username> <password>
9. If all went well, you should see the following screen with a SQL prompt at the end:
+---------------------------------------+
| Connected!                            |
|                                       |
| sql-statement                         |
| help [tablename]                      |
| quit                                  |
|                                       |
+---------------------------------------+
SQL>
10. Close the connection using Ctrl + C.

From here I thought, wrongfully so, that I could use the DSN name (MSSQLTestServer) to make an odbc connection from PHP.

I'm not sure about the 64-bit system. How do I find that out?
0
 
horaliaAuthor Commented:
I typed in uname -m at the command window and i686 came up.
0
 
slyongCommented:
Hi horalia,

Could you tell us how you ./configure php?  If you could give the full parameters that you used.
0
 
slyongCommented:
Hi horalia,

If you are compiling php from source, you also need to install freetds-devel package via:

# yum install freetds-devel
0
 
horaliaAuthor Commented:
These are the commands that I'm using to install freetds, apache and php. I got the instructions from a posting on php.net:

freetds:
./configure --prefix=/usr/local/freetds --with-tdsver=8.0 --enable-msdblib --enable-dbmfix --with-gnu-ld

apache:
./configure --prefix=/etc/httpd --enable-so

php:
./configure --with-apxs2=/etc/httpd/bin/apxs --enable/versioning --with-mssql=/usr/local/freetds --disable-libxml

My problem is that after installing php I can't start httpd once again. I'll install freetds-devel as you suggested, and let you know. Thanks!
0
 
hernst42Commented:
If the apache does not start whats in the error_log of the apache.

If you succeeded with the above configure the freetds-devel is already present
0
 
horaliaAuthor Commented:
How can I look at the error_log in apache?
0
 
horaliaAuthor Commented:
I almost forgot something, in the instructions that I found, it reads: "Configure the file -> httpd.conf" What changes do I need to on this file?
0
 
horaliaAuthor Commented:
OK, here's another error I just found. When verifying apache, I did the following:
/etc/httpd/bin/apachectl start
and I got the following error:
Syntax error on line 148 of /etc/httpd/conf/httpd.conf:
API module structure `auth_basic_module' in file /etc/httpd/modules/mod_auth_basic.so is garbled - perhaps this is not an Apa che module DSO?
0
 
slyongCommented:
Hi horalia,

Just a bit of explaination and get you on the right track.  You have installed freetds via yum (yum install freetds).  This installs the binaries, to enable you to do isql to connect to mssql, and things like that.  

> freetds:
> ./configure --prefix=/usr/local/freetds --with-tdsver=8.0 --enable-msdblib --enable-dbmfix --with-gnu-ld
You actually downloaded the freetds souce and do ./configure.. make, etc.  You don't need that, I would suggest you remove it using
# make uninstall

By installing the freetds-devel (yum install freetds-devel), you have the proper header files for the need of compiling php.  Actually if you install the freetds source (using ./configure, make, make install..) you will have both the binaries and header files also.  However, using yum is a simpler way if you are not familiar with compiling and installing from source.

Next about your apache and php... I can see that you are not familiar with installing from source.  I would suggest you remove them both (again using make uninstall).  Then, let's try to get to you php connection to mssql...  While you can use the source to install apache, php.  They take some work.  php configuration should be with:  --with-mssql[=DIR], where DIR is the FreeTDS install prefix, and --enable-msdblib.

Let's take another path, then yum install way which might just solve your problem like magic.  Again, your dries repository is setup.. do:

# yum install httpd php php-adodb

This will install apache, php and php-adodb.  Then you can try your PHP:

<?php
      $db =& ADONewConnection('odbc_mssql');
      $dsn = "Driver={SQL Server};Server=10.7.122.28;Database=ProdDB;";
      $db->Connect($dsn,'userid','password');
        $rs = $db->Execute("select * from dbo.RPT_Customer");
        while ($array = $rs->FetchRow()) {
            print_r($array);
        }
?>

Let's try that before we go down the installation using source route.
0
 
horaliaAuthor Commented:
OK, I'll do this asap. I'm reloading my machine again, so I'll start fresh. It's almost done. I installed Fedora Core 5 as a Web Server and installed a C++ compiler and Perl I believe... Anyways, just to be sure, I only need to type in this command without downloading anything? The yum install httpd php php-adodb command?
0
 
slyongCommented:
yes.. the yum will do the download and installation for you.
0
 
horaliaAuthor Commented:
OK, I'll install freetds just like I did before and then apache, php and php-adodb just like you suggested. I'll let you know what my results are. Thanks!
0
 
slyongCommented:
No worries horalia.
0
 
horaliaAuthor Commented:
Believe me, I am worried! I've been trying to get this to work for weeks now, and I just got an e-mail from my supervisor asking for a target date to present my project.
0
 
slyongCommented:
Sorry horalia, I am down in Australia and can only answer question during early morning hours or evening hours and no worries is answer for the "thanks" :D.  I hope I could help you get it up and running soon.  Fingers crossed.
0
 
horaliaAuthor Commented:
OK slyong, I have installed freetds just like I described earlier, I have been able to make a connection to my MSSQL server without any problem. I also ran the command # yum install httpd php php-adodb and no errors came up. Unfortunately, the php page came up empty. I first verified that php was working which it is. I also restarted the httpd server and copied your code just to make sure it was exactly the same, but only a blank page shows up.  I also verified the connection using -isql and running a query. Any ideas?
0
 
horaliaAuthor Commented:
slyong, hopefully you will have some advice for me tomorrow, thanks anyways.
0
 
slyongCommented:
Hi horalia,

<?php
     $db =& ADONewConnection('odbc_mssql');
     $dsn = "Driver={SQL Server};Server=10.7.122.28;Database=ProdDB;";
     $db->Connect($dsn,'userid','password') or die("Cannot start ADO");                 // change this line.. to see if the connection get thru...
        $rs = $db->Execute("select * from dbo.RPT_Customer");
        while ($array = $rs->FetchRow()) {
            print_r($array);
        }
?>
0
 
horaliaAuthor Commented:
Nothing. I copied your exact same code and only a blank page comes up. You have no idea how much I regret taking this path....
0
 
slyongCommented:
Sorry horalia,

> Nothing. I copied your exact same code and only a blank page comes up. You have no idea how much I regret taking this path....

All experts are trying to help here.  I regret that you are unhappy about my suggestion.  I will just post my last comment, let me know if you want me to proceed, otherwise, I will leave it to other experts.

Check that you have your userid and password replaced,  try test this code and see what is the result:
<?php
     $db =& ADONewConnection('odbc_mssql');
     $dsn = "Driver={SQL Server};Server=10.7.122.28;Database=ProdDB;";
     $db->Connect($dsn,'userid','password')         // check your userid and password
     if (!$db) die ("Cannot start ADO");                 // change this line.. to see if the connection get thru...
        $rs = $db->Execute("select * from dbo.RPT_Customer");
        while ($array = $rs->FetchRow()) {
            print_r($array);
        }
?>
0
 
horaliaAuthor Commented:
Oh, no, slyong, I'm not happy about your suggestion, it's just that I'm so new to this and I've been trying to get this to work for almost a month, that I'm unhappy about taking this route, not your suggestions! As a matter of fact, you're the only expert that hasn't abandoned the question like so many others! I'm sorry that I took my frustration out on the web site, but please, don't take it as if I were not happy with your comment. I know it must be hard to help someone remotely, specially with a newbie, like me!
0
 
horaliaAuthor Commented:
I'll try out your suggestion and let you know. One question, when looking at a phpinfo() page, will the configuration indicate if mssql is installed?
0
 
horaliaAuthor Commented:
I was just thinking of something, would it be too hard for you to explain to me how to configure and install php? I think that is where the problem lies, since I am to query the MSSQL server using freetds... Please let me know. I was about to reload Fedora Core 5 again before your last comment.
0
 
slyongCommented:
Is ok horalia,

I understand the stress.  On phpinfo() page, you should be able to see the MSSQL section indicated like here http://www.entropy.ch/software/macosx/php/test.php.  Also if possible could you paste the output of the command

# rpm -qa php*

here?
0
 
horaliaAuthor Commented:
Unfortunately nothing happened, blank page again, not even an error message. I verified the username and password using isql and they are correct. I also checked that I was using the correct database name and table.
0
 
horaliaAuthor Commented:
OK, I'll do this, and thank you for understanding, I really appreciate this.
0
 
horaliaAuthor Commented:
I typed it in and there was no outcome:

[root@localhost /]# rpm -qa php*
[root@localhost /]#

Is this what you meant?
0
 
slyongCommented:
Hi horalia,

Let's do this just the final time before we go down the source installation.

Just give you an idea, the source installation needs is:
1) whatever the steps for freetds + freetds-devel
2) remove the php, apache rpms
3) download the php, apache sources
4) follow the steps here: http://www.php.net/manual/en/install.unix.apache2.php (and have to make sure that the mssql supports are enabled for the ./configure part).

I found another source for yum which is better tested and documented for Fedora Core 5 with php, mssql, freetds, etc.  If you are reloading your Fedora Core 5, after loading it, don't install the dries RPMs and freetds from dries.

Do this:

1)
# wget http://remi.collet.free.fr/rpms/fc5.i386/remi-release-1-1.fc5.remi.noarch.rpm 
# rpm -Uvh remi-release-1-1.fc5.remi.noarch.rpm

2)
# yum --enablerepo=remi install php-mssql php

should install php with mssql support and freetds.  The website for remi is here http://remi.collet.free.fr/index.php?2006/06/25/167-php-514-2 (it is in half French / English).

You can think which way you want to go.  My suggestion is still going with yum rather then the source installation.
0
 
horaliaAuthor Commented:
Thanks slyong, I will do as suggested. I left my machine reloading Fedora when I left the office and will start first thing in the morning.
0
 
slyongCommented:
horalia,

after installing the remi php-mssql and php, you have to configure the DSN, ODBC, etc.  Then test your PHP program.  Fingers crossed.
0
 
horaliaAuthor Commented:
Hi slyong, after reloading the machine with Fedora Core 5 as a web server, I followed your instructions. I typed in the following:

# wget http://remi.collet.free.fr/rpms/fc5.i386/remi-release-1-1.fc5.remi.noarch.rpm 
# rpm -Uvh remi-release-1-1.fc5.remi.noarch.rpm
# yum --enablerepo=remi install php-mssql php

What did I exactly install? Is freetds included in this installation?
0
 
horaliaAuthor Commented:
This is what I did next slyong:

--Verified that freeTDS was working with the MSSQL that I wanted to connect to using the following command at root:
#tsql -S <ip address of MSSQL server> -U <password>
--Created a file under root named tds.driver.template with the following lines:
***************************
[FreeTDS]
Description = v0.63 with protocol v8.0
Driver = /usr/lib/libtdsodbc.so.0
****************************
--Executed the following command, which registers the ODBC driver:
#odbcinst -i -d -f tds.driver.template
--Created a second file also under root named tds.datasource.template with the following lines:
*****************************
[MSSQLTestServer]
Driver = FreeTDS
Description = <DB Description>
Trace = No
Server = <MSSQL ip address>
Port = 1433
Database = <DB name>
*******************************
--Executed the following command, which I thinks creates the DSN:
# odbcinst -i -s -f tds.datasource.template -l
--Restarted the server.
--Tried to connect to the server using the following command:
#isql -v MSSQLTestServer <username> <password>
And here I got the following error:

[root@localhost /]# isql -v MSSQLTestServer user pwd
[01000][unixODBC][Driver Manager]Can't open lib '/usr/lib/libtdsodbc.so.0' : /usr/lib/libtdsodbc.so.0: cannot open shared object file: No such file or directory
[ISQL]ERROR: Could not SQLConnect

I'll be working on other projects today and check back and see what your next suggestion is. If this is getting too complicated, and you are more familiar with Fedora Core 4, I can get the disks for this OS and work with this one if you prefer. It really doesn't make a difference to me. Talk to you later....
0
 
slyongCommented:
Hi horalia,

Made a mistake here.  You still need to install freetds from dries.  Remi's website actually stated that but I didn't understand.  Also if you could, put the output of "rpm -qa php*" here so that I could see if all the necessary packages are installed.

Regards
0
 
horaliaAuthor Commented:
Just read your posting. I will do that and let you know. What time is it with you? I'm in the US in Pacific Time, it's July 6th, 1:30 p.m. I'm asking this because if you can answer when it's still night for me, I can stay late at work. I can also IM if you like, and then later, post the complete solution in EE. Let me know...
0
 
slyongCommented:
It is 6:30am here in Sydney, Australia.  It is against EE's policy to take this off EE, may be humeniuk the page editor can see if something else could be arrange to make the communication faster.
0
 
horaliaAuthor Commented:
Oops, didn't know that. No, I guess we can communicate just like we've been doing so far. Following the suggestions takes time anyways, so what I'll do is just detail the steps I did on the server, try out the code, keep my fingers crossed, and let you know the outcome. One more thing, I really appreciate you taking your time and posting at such an early hour for you. If I'm not working, I'm usually asleep at 6 a.m., well, granting that my 1 year old doesn't wake me up, which lately that hasn't been the case, but anyways, just wanted to let you know that I commend your dedication to EE... :-)
0
 
slyongCommented:
thanks horalia,

I normally don't get up this early too but I am a bit worried about you getting the solution out on time.  Hope this final step could get you thru.
0
 
horaliaAuthor Commented:
I believe we will!
0
 
horaliaAuthor Commented:
slyong, I just installed freetds after reloading Fedora, just to be sure that the OS would be all clean. I verified that it was connecting to the MSSQL server by using isql and was able to run a query successfully. So far, so good. I also ran #rpm -qa php and now I did get an outcome, php-5.1.4-1. Here a copy of the terminal:

SQLRowCount returns 14487
14487 rows fetched
SQL> quit
[root@localhost /]# rpm -qa php
php-5.1.4-1
[root@localhost /]#

I'll follow the next steps and post my results...
0
 
horaliaAuthor Commented:
After my last posting I typed in the suggested commands:

# wget http://remi.collet.free.fr/rpms/fc5.i386/remi-release-1-1.fc5.remi.noarch.rpm 
# rpm -Uvh remi-release-1-1.fc5.remi.noarch.rpm
# yum --enablerepo=remi install php-mssql php

Here's a copy of the screen:

SQLRowCount returns 14487
14487 rows fetched
SQL> quit
[root@localhost /]# rpm -qa php
php-5.1.4-1
[root@localhost /]# wget http://remi.collet.free.fr/rpms/fc5.i386/remi-release-1-1.fc5.remi.noarch.rpm
--14:40:05--  http://remi.collet.free.fr/rpms/fc5.i386/remi-release-1-1.fc5.remi.noarch.rpm
           => `remi-release-1-1.fc5.remi.noarch.rpm'
Resolving remi.collet.free.fr... 212.27.63.123
Connecting to remi.collet.free.fr|212.27.63.123|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 4,257 (4.2K) [application/x-rpm]

100%[=====================================================================>] 4,257         25.82K/s

14:40:06 (25.70 KB/s) - `remi-release-1-1.fc5.remi.noarch.rpm' saved [4257/4257]

[root@localhost /]# rpm -Uvh remi-release-1-1.fc5.remi.noarch.rpm
warning: remi-release-1-1.fc5.remi.noarch.rpm: Header V3 DSA signature: NOKEY, key ID 00f97f56
Preparing...                ########################################### [100%]
   1:remi-release           ########################################### [100%]
[root@localhost /]# yum --enablerepo=remi install php-mssql php
Loading "installonlyn" plugin
Setting up Install Process
Setting up repositories
dries                                                                [1/5]
core                                                                 [2/5]
updates                                                              [3/5]
remi                                                                 [4/5]
remi                      100% |=========================|  951 B    00:00
extras                                                               [5/5]
Reading repository metadata in from local files
primary.xml.gz            100% |=========================|  18 kB    00:00
remi      : ################################################## 62/62
Added 62 new packages, deleted 0 old in 0.45 seconds
Parsing package install arguments
Resolving Dependencies
--> Populating transaction set with selected packages. Please wait.
---> Downloading header for php-mssql to pack into transaction set.
php-mssql-5.1.4-2.fc5.rem 100% |=========================|  16 kB    00:00
---> Package php-mssql.i386 0:5.1.4-2.fc5.remi set to be updated
---> Downloading header for php to pack into transaction set.
php-5.1.4-2.fc5.remi.i386 100% |=========================|  18 kB    00:00
---> Package php.i386 0:5.1.4-2.fc5.remi set to be updated
--> Running transaction check
--> Processing Dependency: php-common = 5.1.4-2.fc5.remi for package: php
--> Processing Dependency: php = 5.1.4-1 for package: php-ldap
--> Processing Dependency: php-cli = 5.1.4-2.fc5.remi for package: php
--> Processing Dependency: php-api = 20041225 for package: php-mssql
--> Restarting Dependency Resolution with new changes.
--> Populating transaction set with selected packages. Please wait.
---> Downloading header for php-cli to pack into transaction set.
php-cli-5.1.4-2.fc5.remi. 100% |=========================|  17 kB    00:00
---> Package php-cli.i386 0:5.1.4-2.fc5.remi set to be updated
---> Downloading header for php-ldap to pack into transaction set.
php-ldap-5.1.4-2.fc5.remi 100% |=========================|  16 kB    00:00
---> Package php-ldap.i386 0:5.1.4-2.fc5.remi set to be updated
---> Downloading header for php-common to pack into transaction set.
php-common-5.1.4-2.fc5.re 100% |=========================|  20 kB    00:00
---> Package php-common.i386 0:5.1.4-2.fc5.remi set to be updated
--> Running transaction check

Dependencies Resolved

=============================================================================
 Package                 Arch       Version          Repository        Size
=============================================================================
Installing:
 php-mssql               i386       5.1.4-2.fc5.remi  remi               36 k
Updating:
 php                     i386       5.1.4-2.fc5.remi  remi              1.2 M
Installing for dependencies:
 php-cli                 i386       5.1.4-2.fc5.remi  remi              2.2 M
 php-common              i386       5.1.4-2.fc5.remi  remi              139 k
Updating for dependencies:
 php-ldap                i386       5.1.4-2.fc5.remi  remi               33 k

Transaction Summary
=============================================================================
Install      3 Package(s)
Update       2 Package(s)
Remove       0 Package(s)
Total download size: 3.7 M
Is this ok [y/N]: y
Downloading Packages:
(1/5): php-cli-5.1.4-2.fc 100% |=========================| 2.2 MB    00:03
(2/5): php-ldap-5.1.4-2.f 100% |=========================|  33 kB    00:00
(3/5): php-mssql-5.1.4-2. 100% |=========================|  36 kB    00:00
(4/5): php-5.1.4-2.fc5.re 100% |=========================| 1.2 MB    00:02
(5/5): php-common-5.1.4-2 100% |=========================| 139 kB    00:01
warning: rpmts_HdrFromFdno: Header V3 DSA signature: NOKEY, key ID 00f97f56
Public key for php-cli-5.1.4-2.fc5.remi.i386.rpm is not installed
Retrieving GPG key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi
Importing GPG key 0x00F97F56 "Remi Collet <remi.collet@univ-reims.fr>"
Is this ok [y/N]: y
Key imported successfully
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing: php-common                   ######################### [1/7]
  Installing: php-cli                      ######################### [2/7]
  Updating  : php                          ######################### [3/7]
  Updating  : php-ldap                     ######################### [4/7]
  Installing: php-mssql                    ######################### [5/7]
  Cleanup   : php-ldap                     ######################### [6/7]
  Cleanup   : php                          ######################### [7/7]

Installed: php-mssql.i386 0:5.1.4-2.fc5.remi
Dependency Installed: php-cli.i386 0:5.1.4-2.fc5.remi php-common.i386 0:5.1.4-2.fc5.remi
Updated: php.i386 0:5.1.4-2.fc5.remi
Dependency Updated: php-ldap.i386 0:5.1.4-2.fc5.remi
Complete!
[root@localhost /]#
0
 
horaliaAuthor Commented:
Wow, this question is getting huge...
0
 
horaliaAuthor Commented:
What's next?
0
 
slyongCommented:
Hi horalia,

The next step is to test the php program.. and see if the connection happens in PHP

0
 
slyongCommented:
hey... I assume that you setup the odbc and testing freetds right?
0
 
slyongCommented:
hi horalia,

I will be away for a couple of hours.. be back checking in two hours..
0
 
horaliaAuthor Commented:
You mean by using the isql command? If so, yes, I have.
0
 
horaliaAuthor Commented:
OK, I'll check back later.
0
 
slyongCommented:
yup once you testing with tsql and isql command, you can put in the PHP page to test..
0
 
horaliaAuthor Commented:
OK, I put in a php test page and again, only a blank page comes up. This is the code:

<?php
$connect = odbc_connect("MSSQLTestServer","user","pwd");
if ($connect) die ("Invalid connection");
?>

I included a bogus user to test if the error message came up but it didn't.

I used MSSQLTestServer because that's the name of the DSN I used when setting it up. I also used it when testing the freetds connection with isql.

I also made a phpinfo page, and when that comes up, this line is included in the additional .ini files parsed section. It also indicated --without-unixODBC and --without-ODBC in the configuration.
0
 
slyongCommented:
ok.. let's install the rest of php modules (including php-odbc) by:

yum --enablerepo=remi install php*
0
 
horaliaAuthor Commented:
Will do.
0
 
horaliaAuthor Commented:
Well, we're finally making some progress, I tried the following code:

<?php
$sqlconnect = odbc_connect("MSSQLTestServer","user","pwd");
if (!$sqlconnect) die ("No connection");
$sqlquery = "select dbo.RPT_Customer.Customer_Name FROM dbo.RPT_Customer;";
$process=odbc_exec($sqlconnect, $sqlquery);
if (!$process) die ("Invalid query");
?>

And at least now I get the error message, "No connection."
0
 
horaliaAuthor Commented:
I also tried this code:

<html>
<body>
<?php
$con = mssql_connect("10.7.122.28","user","pwd") or die ("No mssql connection.");
mssql_select_db("RHProdDB",$con) or die ("No db selected.");
$sql = "SELECT * FROM dbo.RPT_Customer;";
$rs = mssql_query($sql, $con);
echo "The field number one is: ";
echo mssql_result($rs, 0, 0);
mssql_close($con);
?>
</body>
</html>

And I also got the error message "No mssql connection."

Well, at least now it's telling us something!
0
 
slyongCommented:
Sorry I am caught up with work..

Try this code:

<html>
<body>
<?php
$con = mssql_connect("10.7.122.28,1433","user","pwd") or die ("No mssql connection.");
mssql_select_db("RHProdDB",$con) or die ("No db selected.");
$sql = "SELECT * FROM dbo.RPT_Customer;";
$rs = mssql_query($sql, $con);
echo "The field number one is: ";
echo mssql_result($rs, 0, 0);
mssql_close($con);
?>
</body>
</html>

Put in the port 1433.
0
 
horaliaAuthor Commented:
No worries slyong. I got just in by the way... I'll try the code asap and see what happens....
0
 
horaliaAuthor Commented:
Error message comes up saying "No mssql connection."
0
 
horaliaAuthor Commented:
slyong, I looked at the httpd error log and I found this:

[Fri Jul 07 10:18:42 2006] [notice] SELinux policy enabled; httpd running as context root:system_r:httpd_t:s0
[Fri Jul 07 10:18:42 2006] [notice] suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
[Fri Jul 07 10:18:42 2006] [notice] Digest: generating secret for digest authentication ...
[Fri Jul 07 10:18:42 2006] [notice] Digest: done
PHP Warning:  Module 'mssql' already loaded in Unknown on line 0
[Fri Jul 07 10:18:43 2006] [notice] mod_python: Creating 4 session mutexes based on 256 max processes and 0 max threads.
[Fri Jul 07 10:18:43 2006] [notice] Apache/2.2.0 (Fedora) configured -- resuming normal operations
[Fri Jul 07 10:18:58 2006] [error] [client 127.0.0.1] Directory index forbidden by Options directive: /var/www/html/
[Fri Jul 07 10:19:04 2006] [error] [client 127.0.0.1] PHP Warning:  odbc_connect() [<a href='function.odbc-connect'>function.odbc-connect</a>]: SQL error: [unixODBC][FreeTDS][SQL Server]Unable to connect to data source, SQL state S1000 in SQLConnect in /var/www/html/phpinfo.php on line 2
[Fri Jul 07 10:19:15 2006] [error] [client 127.0.0.1] PHP Warning:  mssql_connect() [<a href='function.mssql-connect'>function.mssql-connect</a>]: Unable to connect to server:  10.7.122.28 in /var/www/html/slyong.php on line 4
[Fri Jul 07 10:19:22 2006] [error] [client 127.0.0.1] PHP Warning:  mssql_connect() [<a href='function.mssql-connect'>function.mssql-connect</a>]: Unable to connect to server:  10.7.122.28 in /var/www/html/mssql.php on line 4
[Fri Jul 07 10:43:42 2006] [error] [client 127.0.0.1] PHP Warning:  odbc_connect() [<a href='function.odbc-connect'>function.odbc-connect</a>]: SQL error: [unixODBC][FreeTDS][SQL Server]Unable to connect to data source, SQL state S1000 in SQLConnect in /var/www/html/phpinfo.php on line 2

Maybe this will pinpoint us in the right direction. The mssql section on the phpinfo page looks fine.
0
 
sleep_furiouslyCommented:
Since you can connect from the command line but not from the httpd service, it looks like there is a good chance SELinux is blocking it.

Try disabling SELinux.  Typically this means go to:
/etc/selinux/config

And set:
SELINUX=disabled

Then reboot.
0
 
sleep_furiouslyCommented:
If SELINUX is the problem and you need to have it running, you can try to fix the setting in question.

A likely solution is to configure with this command:

/usr/sbin/setsebool -P httpd_can_network_connect=1
0
 
horaliaAuthor Commented:
I'll try out your suggestion sleep_furiosly. Thanks!
0
 
horaliaAuthor Commented:
Hi, unfortunately, your comment didn't make a difference sleep. Could it be on the server side where the problem is? I'm able to connect to the server using odbc functions without any problem from a Windows XP box, and also from the terminal window, so I believe it is really from a PHP standpoint. Could I possibly have the instructions to configure and install PHP including mssql? From my limited Linux knowledge, I know the command is:
./configure --with-mssql=... (path where mssql is located, in this case, freetds).

I also had a recommendation from an instructor to use adodb located in adodb.sourceforge.net. Has anyone ever used these drivers?
0
 
horaliaAuthor Commented:
Well, I finally got it to work. Well, I shouldn't say "I", it was another person that was able to make a connection in a few minutes. What he did was install freetds and php-mssql from rpms using yum. This is where the rpms are located:

http://easynews.dl.sourceforge.net/sourceforge/phprpms/freetds-0.63-2.i386.rpm
http://easynews.dl.sourceforge.net/sourceforge/phprpms/php-mssql-5.0.4-10.1.i386.rpm

He then modified /etc/yum.config and php.ini., started apache and that was it. I'll copy all the text in the terminal window in case somebody gets stuck with this like me.
0
 
horaliaAuthor Commented:
Well, first the rpm download:

wget http://easynews.dl.sourceforge.net/sourceforge/phprpms/freetds-0.63-2.i386.rpm
wget http://easynews.dl.sourceforge.net/sourceforge/phprpms/php-mssql-5.0.4-10.1.i386.rpm

I downloaded the files in /usr/src

This is the command window after he took over:

[root@localhost src]# man yum
Formatting page, please wait...
[root@localhost src]# vi /etc/yum.conf
[root@localhost src]# yum localinstall freetds-0.63-2.i386.rpm
Setting up Local Package Process
Examining freetds-0.63-2.i386.rpm: freetds - 0.63-2.i386
Marking freetds-0.63-2.i386.rpm to be installed
Resolving Dependencies
--> Populating transaction set with selected packages. Please wait.
---> Package freetds.i386 0:0.63-2 set to be updated
--> Running transaction check
Setting up repositories
updates-released          100% |=========================|  951 B    00:00
extras                    100% |=========================| 1.1 kB    00:00
base                      100% |=========================| 1.1 kB    00:00
Reading repository metadata in from local files
--> Processing Dependency: libreadline.so.4 for package: freetds
--> Restarting Dependency Resolution with new changes.
--> Populating transaction set with selected packages. Please wait.
---> Package compat-readline43.i386 0:4.3-2 set to be updated
--> Running transaction check

Dependencies Resolved

=============================================================================
 Package                 Arch       Version          Repository        Size
=============================================================================
Installing:
 freetds                 i386       0.63-2           freetds-0.63-2.i386.rpm  3. 8 M
Installing for dependencies:
 compat-readline43       i386       4.3-2            base               89 k

Transaction Summary
=============================================================================
Install      2 Package(s)
Update       0 Package(s)
Remove       0 Package(s)
Total download size: 3.9 M
Is this ok [y/N]: y
Downloading Packages:
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing: compat-readline43            ######################### [1/2]
  Installing: freetds                      ######################### [2/2]

Installed: freetds.i386 0:0.63-2
Dependency Installed: compat-readline43.i386 0:4.3-2
Complete!
[root@localhost src]# yum localinstall php-mssql-5.0.4-10.1.i386.rpm
Setting up Local Package Process
Examining php-mssql-5.0.4-10.1.i386.rpm: php-mssql - 5.0.4-10.1.i386
Marking php-mssql-5.0.4-10.1.i386.rpm to be installed
Resolving Dependencies
--> Populating transaction set with selected packages. Please wait.
---> Package php-mssql.i386 0:5.0.4-10.1 set to be updated
--> Running transaction check

Dependencies Resolved

=============================================================================
 Package                 Arch       Version          Repository        Size
=============================================================================
Installing:
 php-mssql               i386       5.0.4-10.1       php-mssql-5.0.4-10.1.i386.r pm   45 k

Transaction Summary
=============================================================================
Install      1 Package(s)
Update       0 Package(s)
Remove       0 Package(s)
Total download size: 45 k
Is this ok [y/N]: y
Downloading Packages:
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing: php-mssql                    ######################### [1/1]

Installed: php-mssql.i386 0:5.0.4-10.1
Complete!
[root@localhost src]# cd /etc
[root@localhost etc]# cd httpd
[root@localhost httpd]# ls
conf  conf.d  logs  modules  run
[root@localhost httpd]# cd conf
[root@localhost conf]# locate php.ini
/etc/php.ini
[root@localhost conf]# cd ..
[root@localhost httpd]# vi php.ini
[root@localhost httpd]# cd /etc
[root@localhost etc]# vi php.ini
[root@localhost etc]# locate mssql
/usr/share/pear/DB/mssql.php
/usr/src/php-mssql-5.0.4-10.1.i386.rpm
/root/.Trash/php-mssql-5.0.4-10.1.i386 (copy).rpm?use_mirror=mesh
/root/.Trash/php-mssql-5.0.4-10.1.i386.rpm.1
/root/.Trash/php-mssql-5.0.4-10.1.i386.rpm?use_mirror=mesh
/root/.Trash/php-mssql-5.0.4-10.1.i386.rpm
/root/.Trash/php-mssql-5.0.4-10.1.i386.rpm?use
[root@localhost etc]# updatedb
[root@localhost etc]# locate mssql
/etc/php.d/mssql.ini
/usr/lib/php/modules/mssql.so
/usr/share/pear/DB/mssql.php
/usr/src/php-mssql-5.0.4-10.1.i386.rpm
/root/.Trash/php-mssql-5.0.4-10.1.i386 (copy).rpm?use_mirror=mesh
/root/.Trash/php-mssql-5.0.4-10.1.i386.rpm.1
/root/.Trash/php-mssql-5.0.4-10.1.i386.rpm?use_mirror=mesh
/root/.Trash/php-mssql-5.0.4-10.1.i386.rpm
/root/.Trash/php-mssql-5.0.4-10.1.i386.rpm?use
[root@localhost etc]# vi php.ini
[root@localhost etc]# apachectl start
0
 
horaliaAuthor Commented:
As you can see, he modified two files, yum.config and php.ini. These is yum.config:

[main]
cachedir=/var/cache/yum
debuglevel=2
logfile=/var/log/yum.log
pkgpolicy=newest
distroverpkg=redhat-release
tolerant=1
exactarch=1
retries=20
obsoletes=1
gpgcheck=0

# PUT YOUR REPOS HERE OR IN separate files named file.repo
# in /etc/yum.repos.d
0
 
horaliaAuthor Commented:
As for php.ini, he only added the following line in the extension section:

extension=mssql.so

You also have to verify that extension_dir has the correct path where the file mssql.so is located.

You will know right away if the rpms are installed correctly, there is a complete! statement after the yum localeinstall command is done. When I was doing it, I never got that message.

And that's it! Here's the code he used to verify the connection:

<?php
$msconnect = mssql_connect("<server IP address>:<port, usually 1433>","<username>","<password>");
$msdb = mssql_select_db("<database name>",$connect);
$msquery = "select * <some table>";
$msresults = mssql_query($msquery);
while ($row = mssql_fetch_array($msresults))
{
  echo "<li>" . $row['<field 1>'] . " " . $row['<field 2>'] . "</li>\n";
}
?>

And that was it!
0
 
horaliaAuthor Commented:
slyong, since you helped so much I'll award you the points.
0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 47
  • 20
  • 3
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now