Skip to Content.
Sympa Menu

freetds - Re: [freetds] tsql works but php does not?

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: "Bing Du" <bdu AT iastate.edu>
  • To: "FreeTDS Development Group" <freetds AT lists.ibiblio.org>
  • Subject: Re: [freetds] tsql works but php does not?
  • Date: Mon, 21 Nov 2005 14:05:18 -0600 (CST)

> The included script does not retreive any data.
>
> $query_result will have a handle to the query (on success) and should be
> used as a parameter to mssql_fetch_row() or one of the other fetch
> functions to retreive the data.
>
> example:
>
> <?php
>
> $con = mssql_connect($server, $user, $pass);
> if ($con) {
> mssql_select_db($database, $con);
>
> $rs = mssql_query(*select * from mytable", $con);
> if (is_resource($rs)) {
> while ($row = mssql_fetch_row($rs)) {
> print_r($row);
> }
> }
> }

Dang, that should be an obvious error. I just copied and pasted that code
snippet from a website without looking very closely. But that's not it.
I later noticed php-mssql extension was not installed. Even after
php-mssql extension was installed, it still did not work with the FreeTDS
I downloaded from http://www.freetds.com. Then I noticed
freetds-0.63-2.i386.rpm was provided along with the php-mssql extension
rpm on http://www.php.net. I downloaded that and installed and all is
fine now.

By default, FreeTDS from freetds.com installs libsybdb.so.5 in
/usr/local/lib. But FreeTDS from php.net installs in /usr/lib.

Thanks all who replied.

Bing
>
> mssql_close($con);
>
> ?>
>
> - Frank
>
>> Hello,
>>
>> Freetds-0.63 installed. TSQL can connect to the MS SQL server and pull
>> the data out fine. But the following php script returns nothing either
> on
>> command link or in web browser. No error messages even. What am I
>> missing? Thanks in advance for any help.
>>
>> ==
>> <?php
>>
>> // connect to database server
>> $db_conn = mssql_connect("MyServer2k","user","pass")
>> or die( "<strong>ERROR: Connection to mssql failed</strong>" );
>>
>> // select database - only if we want to query another database than
> the
>> default one
>> mssql_select_db( "somedb", $db_conn )
>> or die( "<strong>ERROR: Selecting database failed</strong>" );
>>
>> // query the database
>> $query_result = mssql_query( "SELECT * FROM somedb", $db_conn )
>> or die( "<strong>ERROR: Query failed</strong>" );
>>
>> /*
>> * You can now access the result data by using the appropriate
>> mssql_xxx() functions
>> * on $query_result. See the PHP manual section on Microsoft SQL
> Server
>> functions
>> * for documentation on how to do this.
>> */
>>
>> mssql_free_result( $query_result ); // unnecessary in PHP 4
>>
>> mssql_close( $db_conn ); // unnecessary in PHP 4
>> ?>
>> ==
>>
>> /usr/local/etc/freetds.conf
>>
>> ==
>> ...
>> [MyServer2k]
>>
>> host = mssql.some.edu
>> port = 1433
>> tds version = 8.0
>> dump file = /tmp/freetds.log
>> dump file append = yes
>> ...
>> ==
>>
>> Bing
>> _______________________________________________
>> FreeTDS mailing list
>> FreeTDS AT lists.ibiblio.org
>> http://lists.ibiblio.org/mailman/listinfo/freetds
>>
>
>
>
> _______________________________________________
> FreeTDS mailing list
> FreeTDS AT lists.ibiblio.org
> http://lists.ibiblio.org/mailman/listinfo/freetds
>





Archive powered by MHonArc 2.6.24.

Top of Page