Jump to content

mysql_* versus mysqli_*


ptanewbe

Recommended Posts

Hi all, I am new to this (programmed on mainframe many years).  I created a dropdown selection populated from an SQL table.  my problem is if I use mysql_*, the selection is populated and works correct but if I change the mysql_* to mysqli_*, it will not work (I know my connect and slect database work, because i do not go into "or die" part). My coding below:

                $intIdField = 'code';
                $strNameField = 'name';
                $strTableName = 'country';
                $strNameOrdinal = 'name';
                $strMaskName = 'select country';
                $strOrderField = 'name';
                $strMethod="ASC";
                echo "<select name=\"$strNameOrdinal\">\n";
                echo "<option value=\"NULL\">".$strMaskName."</option>\n";
                $strQuery = "select $intIdField, $strNameField
                    from $strTableName
                    order by $strOrderField $strMethod";
                if (!$strQuery) {
                    die("query failed:" . mysql_error());
                }
                echo
                mysql_query ("set character_set_results='utf8'");
                $rsrcResult = mysql_query($strQuery);
                while($arrayRow = mysql_fetch_assoc($rsrcResult)) {
                    echo $row["name"];
                    echo $row["code"];
                $strA = $arrayRow["$intIdField"];
                $strB = $arrayRow["$strNameField"];
                echo "<option value=\"$strA\">$strB</option>\n";
                }
                echo "</select>";

 

It only populates the block with "select country" but if you click on the down arrow, notyhing comes up.  as I say, the above coding work but as soon as I change to mysqli, it does not, what am I doing wrong?

 

Thank you in advance

Link to comment
https://forums.phpfreaks.com/topic/287865-mysql_-versus-mysqli_/
Share on other sites

since you didn't post the mysqli_ version of the code, how could we possibly help with what might be wrong with that version of the code?

 

also, in the following code, why are you testing the sql query statement string variable? -

    if (!$strQuery) {
                    die("query failed:" . mysql_error());
                }

all that code is doing is testing if the sql string is true/false.

You're going to have to do a lot of work. But let's start off with this first. I turned your code into $mysqli and I tested it and I found that $row doesn't exist in the while.

Where is it coming from?

Also you should never echo out your errors. It should only be used during your debugging process. Otherwise, you should never put it live.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.