I moved database from mysql to ms sql server, and now I need to migrate the PHP code. I'm using PHP 7.0.33.
My problem is that mysql code worked on single rows of data, so after fetching data into a resource, inside the loop each row was returned via $r->data_seek($i)
and then worked on via a series of procedures.
For my new ms sql server code, I need to use functions sqlsrv_fetch_array
, sqlsrv_fetch_object
, etc., and seems like there is no concept of a row.
For example, I replaced original code with this and it works:
$r = sqlsrv_query($db_conn, $sql, array(), array( "Scrollable" => 'static' ));
$col_max = sqlsrv_num_fields($res);
while (sqlsrv_fetch($res)) {
for($i = 0; $i < $col_max; $i++) {
$$key = sqlsrv_get_field($res, $i);
}
}
But changing whole program like this - bit by bit, is just very painful. How can I change original code (mysql based), so that I get to reuse existing row by row passing functionality?
My most current problem is how to replace this mysql code with ms sql server:
$r = result
$i = row number to return
function fetch_sql_mysqli_row ($r, $i, $db_conn = null)
{
if ($i >= $r->num_rows)
{
$r->close();
return 0;
}
$r->data_seek($i);
return $r->fetch_row();
}
I'm new to PHP, my background is in Oracle world, hence I apologise in advance if my question can be perceived as dumb or naive.
Many thanks in advance.