Click here to Skip to main content
15,880,392 members
Home / Discussions / Web Development
   

Web Development

 
QuestionDeployments Pin
#realJSOP27-Feb-21 4:57
mve#realJSOP27-Feb-21 4:57 
QuestionASP.Net Web API Controller Question Pin
Kevin Marois26-Feb-21 7:47
professionalKevin Marois26-Feb-21 7:47 
QuestionPHP7+, working with datetime stored in cookie with json format Pin
jkirkerx17-Feb-21 11:48
professionaljkirkerx17-Feb-21 11:48 
QuestionMessage Closed Pin
14-Feb-21 10:11
ellaluceero14-Feb-21 10:11 
AnswerRe: How To create a table in MS Access contain more than 255 filed ? Pin
Richard Deeming14-Feb-21 22:05
mveRichard Deeming14-Feb-21 22:05 
QuestionBootstrap - How do I make an icon a href link Pin
Jim McElhiney10-Feb-21 15:33
Jim McElhiney10-Feb-21 15:33 
AnswerRe: Bootstrap - How do I make an icon a href link Pin
Peter_in_278012-Feb-21 13:58
professionalPeter_in_278012-Feb-21 13:58 
QuestionPHP V7.4.14, convert this database function, understanding mssql_fetch_field to sqlsrv_fetch Pin
jkirkerx10-Feb-21 9:36
professionaljkirkerx10-Feb-21 9:36 
I'm trying to convert this function written in V4.7.3 to V7.4.

This function is used quite often in the app. I get what it does in a general sense, but not at expert level, because I lost my expert PHP database skills back in 2005.

I'm struggling to translate mssql_fetch_field. I tried sqlsrv_fetch_array and the result was 1. Then I tried sqlsrv_get_field and the result was 1.

The webpage errors say:
meta= 1
Notice: Trying to get property 'name' of non-object in C:\App\Dev\PCAD\class\cls_db_tools.php on line 137
Notice: Trying to get property 'name' of non-object in C:\App\Dev\PCAD\class\cls_db_tools.php on line 141
meta= 1
I don't understand the 1 that was returned. Obviously 1 doesn't contain a name, and I expected $meta to be a result.
And I don't have the old dev server to go back to to see what it's suppose to return with the old code.

Here's the old function
function db_Sel_Query($sqlQuery) {

<pre>
$Rows = Array();
$resQuery = mssql_query($sqlQuery) or die();
$cRows = mssql_num_rows($resQuery);
$cFields = mssql_num_fields($resQuery);

$rgFields = Array();
for ($i = 0; $i < $cFields; $i++) {
    $meta = mssql_fetch_field($resQuery);
    $rgFields[$i] = $meta->name;
}

for ($i = 0; $i < $cRows; $i++) {
$row = mssql_fetch_row($resQuery);
for ($col = 0;$col < $cFields;$col++) {
$Rows[$i][$rgFields[$col]] = rtrim($row[$col]);
}
}
mssql_free_result($resQuery);
return $Rows;

}

The new function I wrote
C#
public static function dbSelectQuery($sqlQuery): array {

<pre>
$Rows = array();
$rgFields = array();
$params = array();
$options =  array( "Scrollable" => SQLSRV_CURSOR_KEYSET );

$conn = clsDbConnect::createConn();
$resQuery = sqlsrv_query($conn, $sqlQuery, $params, $options) or die();
$rowCount = sqlsrv_num_rows($resQuery);
$fieldCount = sqlsrv_num_fields($resQuery);

for ($i = 0; $i < $fieldCount; $i++) {

    $meta = sqlsrv_fetch_array($resQuery, SQLSRV_FETCH_ASSOC, $i);
    // $meta = sqlsrv_get_field($resQuery, $i);
    echo "<div>meta= " . print_r($meta) . "</div>";
    if ($meta->name) {
        echo "<div>meta.name= $meta->name</div>";
    }

    $rgFields[$i] = $meta->name;

}

for ($i = 0; $i < $rowCount; $i++) {

$row = sqlsrv_fetch_array($resQuery,SQLSRV_FETCH_NUMERIC);
for ($col = 0; $col < $fieldCount; $col++) {
$Rows[$i][$rgFields[$col]] = rtrim($row[$col]);
}

}

sqlsrv_free_stmt($resQuery);
return $Rows;

}

If it ain't broke don't fix it
Discover my world at jkirkerx.com

AnswerRe: PHP V7.4.14, convert this database function, understanding mssql_fetch_field to sqlsrv_fetch Pin
jkirkerx12-Feb-21 13:14
professionaljkirkerx12-Feb-21 13:14 
Questionphp 7.4.14 convert smalldatetime to string for html display Pin
jkirkerx9-Feb-21 12:14
professionaljkirkerx9-Feb-21 12:14 
AnswerRe: php 7.4.14 convert smalldatetime to string for html display Pin
Richard Deeming9-Feb-21 22:00
mveRichard Deeming9-Feb-21 22:00 
GeneralRe: php 7.4.14 convert smalldatetime to string for html display Pin
jkirkerx10-Feb-21 5:19
professionaljkirkerx10-Feb-21 5:19 
GeneralRefresh a div with pjax Pin
Member 150664316-Feb-21 9:32
Member 150664316-Feb-21 9:32 
GeneralRe: Refresh a div with pjax Pin
OriginalGriff6-Feb-21 9:45
mveOriginalGriff6-Feb-21 9:45 
Question500 Error Pin
#realJSOP4-Feb-21 5:49
mve#realJSOP4-Feb-21 5:49 
AnswerRe: 500 Error Pin
Richard Deeming4-Feb-21 5:59
mveRichard Deeming4-Feb-21 5:59 
GeneralRe: 500 Error Pin
#realJSOP4-Feb-21 7:33
mve#realJSOP4-Feb-21 7:33 
GeneralRe: 500 Error Pin
Richard Deeming4-Feb-21 21:42
mveRichard Deeming4-Feb-21 21:42 
GeneralRe: 500 Error Pin
#realJSOP7-Feb-21 9:08
mve#realJSOP7-Feb-21 9:08 
QuestionVS code/Live Server Browser issue Pin
ISHYY4-Feb-21 4:42
ISHYY4-Feb-21 4:42 
Questiondeployment using "FTP Passive" Pin
Super Lloyd4-Feb-21 1:56
Super Lloyd4-Feb-21 1:56 
QuestionPHP 7.4, best practice to establish a database connection Pin
jkirkerx2-Feb-21 8:10
professionaljkirkerx2-Feb-21 8:10 
QuestionWhich will be the best web development course for kids? Pin
Annet Rose13-Jan-21 23:35
Annet Rose13-Jan-21 23:35 
AnswerRe: Which will be the best web development course for kids? Pin
Richard MacCutchan14-Jan-21 0:37
mveRichard MacCutchan14-Jan-21 0:37 
RantHTML Emails - Printing Pin
Gripper 1070963823-Dec-20 6:08
Gripper 1070963823-Dec-20 6:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.