mysql_* versus mysqli_*

I am new to web programming and I have a little problem I do not understand. I have a drop down selection which works fine when using mysql_* but as soon as I replace the mysql_* with mysqli_* it does not work it only populates the selection box with ‘select country’ but nothing comes up. I know my connect and select database part work because I do not go into the ‘or die’ option. Here is my codeing with mysql_* which work but will not work if changed to mysqli_*
$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."\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\n";
}
echo “”;

You should always display all errors when developing.

Add this to the beginning of the file
[php]ini_set(‘error_reporting’, E_ALL);
ini_set(‘display_errors’, ‘1’);[/php]

You need to post the code that doesn’t work as you had it. Posting code that works won’t help to see what you did wrong.

When I moved from mysql to mysqli I had to

[php]$conn = mysql_connect($this->SERVER,$this->USERNAME,$this->PASSWORD);
// Changed to
$conn = new mysqli($this->SERVER,$this->USERNAME,$this->PASSWORD);

$results = mysql_query($sql,$conn);
// Changed to
$results = mysqli_query($conn,$sql);[/php]

You need to change all your old MySQL calls to MySQLi, not just the connection parameters.

Sponsor our Newsletter | Privacy Policy | Terms of Service