Re: DB_FETCHMODE_ASSOC result differs for MySQL and MS-SQL

From: Date: Mon, 20 Jan 2003 05:58:10 +0000
Subject: Re: DB_FETCHMODE_ASSOC result differs for MySQL and MS-SQL
References: 1 2  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-3353@lists.php.net to get a copy of this message
Thanks Markus, The 'twist' in DB/mssql.php in the function DB_MSSQL from: if ($fetchmode & DB_FETCHMODE_ASSOC) { $ar = @mssql_fetch_array($result); <-- To: if ($fetchmode & DB_FETCHMODE_ASSOC) { $ar = @mssql_fetch_assoc($result); <-- made my day! Things are now working under MS-SQL like under MySQL. But shouldn't this be part of a functioning PEAR version? I am going PEAR, but it has to evolve a lot!!! Documentation, Installation etc. And maybe some advise on the different data types for different DBs. And the PEAR installation is really a trial on error. I wonder how normal human beings will understand how to install it. Downloaded go-pear.php and found somewhere the right instructions to put the right parameters into this file, it is working fine. But there are nowhere real complete instructions. One has to know that you need to get the script/pear.in from somewhere and rename it and ... I bet there will be soon a nice browser based front-end! After all we are using browsers here. There is still a long way to go to make PEAR close to user friendly! But it will be! No doubt! For the time being .. Thank God I know FORTRAN ;-) At least I used to! Gunther "Markus Wolff" <wolff@21st.de> wrote in message news:20030118163135.6227.WOLFF@21st.de... On Sat, 18 Jan 2003 06:17:24 -0400 "Gunther" <g@guntherrichter.com> wrote: > I have a problem with PHP 4.3.0, latest PEAR running under w2k with either > MySQL or MS-SQL. With MySQL everything is fine, running the same application > just > changing the DB server to MS-SQL I get different results. > > I am using fetchRow(DB_FETCHMODE_ASSOC) to get my DB rows. > Under MySQL (correct) a row would look like this: > 'fieldname' => value (e.g. [whateverfield] => 9 ) > > Under MS-SQL I get: > 0 => value 'fieldname' => value (e.g. [0] => 9 [whateverfield] => 9 ) > > It seems that under MS-SQL DB_FETCHMODE_ASSOC AND DB_FETCHMODE_ORDERED > are both on at the same time. Hi Gunther, PEAR::DB´s MSSQL driver uses mysql_fetch_array() when you´re using DB_FETCHMODE_ASSOC - it is normal for this function to behave this way. The driver does this because in PHP versions previous to PHP 4.3.0 it was not possible to compile the MSSQL extension under Linux. Instead, you had to use the Sybase extension, which is sort of compatible to MSSQL, but does not provide the complete set of functions. A possible solution is writing you own driver class. Make a new file that is called "myMSSQL.php" (or something you like better). Now write this piece of code into the new file: // Begin code require_once('DB/mssql.php'); class DB_myMSSQL extends DB_mssql { function fetchInto($result, &$ar, $fetchmode, $rownum=null) { if ($rownum !== null) { if (!@mssql_data_seek($result, $rownum)) { return null; } } if ($fetchmode & DB_FETCHMODE_ASSOC) { $ar = @mssql_fetch_assoc($result); } else { $ar = @mssql_fetch_row($result); } if (!$ar) { /* This throws informative error messages, don't use it for now if ($msg = mssql_get_last_message()) { return $this->raiseError($msg); } */ return null; } return DB_OK; } } // End code Now you have created a new driver class that uses the function mssql_fetch_assoc() instead of mssql_fetch_array(). The new driver should behave as intended, but will not work when used on Linux systems with a PHP version that is using the --with-sybase option instead of --with-mssql (all versions below 4.3.0). On Windows systems, it should always work. You can use your new driver by simply modifying your DSN like this: $db = DB::connect('myMSSQL://user:pwd@dbserver/dbname'); Regards, Markus -- Markus Wolff <wolff@21st.de>

« previous php.pear.general (#3353) next »