Delicious Bookmark this on Delicious Share on Facebook SlashdotSlashdot It! Digg! Digg



PHP : Function Reference : Microsoft SQL Server Functions : mssql_fetch_assoc

mssql_fetch_assoc

Returns an associative array of the current row in the result (PHP 4 >= 4.2.0, PHP 5, PECL odbtp:1.1.1-1.1.4)
array mssql_fetch_assoc ( resource result_id )

Examples ( Source code ) » mssql_fetch_assoc

<?php
// Send a select query to MSSQL
$query mssql_query('SELECT [username], [name] FROM [php].[dbo].[userlist]');

// Check if there were any records
if(!mssql_num_rows($query))
{
    echo 
'No records found';
}
else
{
    
// Print a nice list of users in the format of:
    // * name (username)

    
echo '<ul>';

    while(
$row mssql_fetch_assoc($query))
    {
        echo 
'<li>' $row['name'] . ' (' $row['username'] . ')</li>';
    }

    echo 
'</ul>';
}

// Free the query result
mssql_free_result($query);
?>

Code Examples / Notes » mssql_fetch_assoc

pegas1981

[quote]
WARNING:
PHP 4.3.4 introduced a BUG.
if the DB has: '' (empty string)
this function will return: ' ' (string with 1 space)
see: http://bugs.php.net/bug.php?id=26315
[/quote]
the same version PHP 5.2.0


brandonkirsch

We are running FreeTDS on a Linux Apache / PHP server and encountered the following error when calling mssql_fetch_assoc()
Fatal error: Call to undefined function mssql_fetch_assoc()
We were confused because *some* of the mssql commands worked, such as mssql_connect and mssql_fetch_array.  The trick to make mssql_fetch_assoc() work lies in configuring FreeTDS.  We had to change the statement to contain the --enable-msdblib switch:
./configure --enable-msdblib
We then recompiled PHP to include --with-mssql=/path/to/freetds and finally mssql_fetch_assoc() began working properly.


electricsurfer.com

WARNING:
PHP 4.3.4 introduced a BUG.
if the DB has: '' (empty string)
this function will return: ' ' (string with 1 space)
see: http://bugs.php.net/bug.php?id=26315


php

WARNING: as of PHP 4.3.2
The keys in the array will only contain the 1st 30 characters of the column name if you have column names longer than that.


ben

The 30 character field name limit is still an issue as of PHP 5.1.6, at least running under IIS.

25-mar-2007 06:25

regarding 'The 30 character field name limit is still an issue'
Thought about using shorter column names and using the description to give more info regarding the column.
as to the
$result = mssql_query('SELECT articles.id, issues.id FROM articles, issues WHERE articles.pub_date = issues.pub_date');
try this
$result = mssql_query('SELECT articles.id as aid, issues.id as iid FROM articles, issues WHERE articles.pub_date = issues.pub_date');


jbarker

Beware when using mssql_fetch_assoc() to return data pulled in from joined tables; if the tables have the same column names, the column mentioned last will overwrite the prior one when populating the assoc.
Example:
<?
$result = mssql_query('SELECT articles.id, issues.id FROM articles, issues WHERE articles.pub_date = issues.pub_date');
$record = mssql_fetch_assoc($result);
print_r($record);
/*
Prints:
Array
(
   [id] => 123
)
*/
?>


Change Language


Follow Navioo On Twitter
mssql_bind
mssql_close
mssql_connect
mssql_data_seek
mssql_execute
mssql_fetch_array
mssql_fetch_assoc
mssql_fetch_batch
mssql_fetch_field
mssql_fetch_object
mssql_fetch_row
mssql_field_length
mssql_field_name
mssql_field_seek
mssql_field_type
mssql_free_result
mssql_free_statement
mssql_get_last_message
mssql_guid_string
mssql_init
mssql_min_error_severity
mssql_min_message_severity
mssql_next_result
mssql_num_fields
mssql_num_rows
mssql_pconnect
mssql_query
mssql_result
mssql_rows_affected
mssql_select_db
eXTReMe Tracker