I'm just (very belatedly I know) updating some of my code from mysql to mysqli and I've noticed what seems to be a change in behaviour in the fetch_array function.
There was no intention to obfuscate by truncating the code in the original question, but here if it helps is a fuller run down of the actual code.
USING : MYSQL
THIS STEPS THROUGH EACH QUALIFY RECORD IN THE TABLE FROM FIRST TO LAST
$con_head = mysql_connect($domain,$head_dbname,$head_dbpassword);
if (!$con_head)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db($head_dbname, $con_head);
$src_sql = "Select * from SEQUENCES where SEQUENCE_TYPE = 'N' and REVIEWED ='N' order by SEQ_START";
$src_tb = mysql_query($src_sql, $con_head);
while ($src_rec = mysql_fetch_array($src_tb))
{
..... statements here have no relevance to the problem
}
USING MYSQLI
**THIS IMMEDIATELY SKIPS THE WHILE CLAUSE **
IF THE ROW IMMEDIATELY ABOVE WHILE IS UNCOMMENTED - THIS PROCEEDS BUT STARTING FROM THE SECOND RECORD.
$con_head = mysqli_connect("$domain,$head_dbname,$head_dbpassword,$head_dbname); // database name and user name are the same
if (!$con_head)
{
die('Could not connect: ' . mysqli_error());
}
$src_sql = "Select * from SEQUENCES where SEQUENCE_TYPE = 'N' and REVIEWED ='N' order by SEQ_START ";
$src_tb = mysqli_query($con_head, $src_sql);
// $src_rec = mysqli_fetch_array($src_tb,MYSQLI_BOTH);
while ($src_rec = mysqli_fetch_array($src_tb,MYSQLI_BOTH))
{
..... statements here have no relevance to the problem
}
This works fine under mysql , but the equivalent under mysqli immediately fails the "while" test.
I've checked that otherwise the code is okay, by inserting an additional mysqli_fetch_array before commencing the loop, this works fine - although starts the processing therefore from the SECOND record.
Clearly I can rewrite my code to loop in a different way (eg having $record = mysqli_fetch_array BEFORE THE loop, having the loop testing $record and then an additional $record = mysqli_fetch_array before the end curly brace in the while loop) but I'm anxious to understand the difference in behaviour so that I don't run into any other pitfalls.
Can anyone explain?