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
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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.