I am trying to convert this PDO to Mysqli. I am a PHP noob and have been learning mysqli this whole time. However this snippet of code is in PDO and i need to make it mysqli.
Here is the original PDO code:
$connect = new PDO("mysql:host=localhost; dbname=testing;", "root", "");
function fill_select_box($connect, $category_id)
{
$query = "
SELECT * FROM team";
$statement = $connect->prepare($query);
$statement->execute();
$result = $statement->fetchAll();
$output = '';
foreach($result as $row)
{
$output .= '<option value="'.$row["id"].'">'.$row["teamname"].'</option>';
}
return $output;
}
Here is my attempt at changing it to mysqli:
$connect= new mysqli('localhhost', 'root', '', 'testing');
if(!$connect){
die(mysqli_error($connect));
}
function fill_select_box($connect, $category_id){
$sql="SELECT * FROM team";
$result=mysqli_query($connect,$sql);
while ($row = mysqli_fetch_assoc($result)){
echo '<option value="'.$row["id"].'">'.$row["teamname"].'</option>';
}
}
Am i missing anything or am I correct with my conversion?