Jump to content

Problem moving to mysqli


SF23103

Recommended Posts

I am trying to be good and re-write all of my scripts to use mysqli instead of mysql_query & mysql_result etc.  I have written the code below, but I am stuck.  

 

Here's an explanation:

 while($row = $result->fetch_assoc()){
 echo $row['col_1'] ;
 }

results echo's "ON" or "OFF" based on the settings of another app.  I want to assign that result (ON or OFF) to a variable $status.  I will then use that to do something else:

if ($status == 'OFF' ) $display_this = 'on.gif' ;
if ($status == 'ON' ) $display_this = 'off.gif';

Here is the code I have written so far:

<?php include "database_login.php";

$db = new mysqli('localhost', $username, $password, $database);

if($db->connect_errno > 0){
    die('Unable to connect to database [' . $db->connect_error . ']');
}

$sql = <<<SQL
    SELECT *
    FROM `ft_data_18`
SQL;

if(!$result = $db->query($sql)){
    die('There was an error running the query [' . $db->error . ']');
}

 while($row = $result->fetch_assoc()){
 echo $row['col_1'] ;
 }
$db->close(); ?>


Link to comment
https://forums.phpfreaks.com/topic/284728-problem-moving-to-mysqli/
Share on other sites

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.