MySQL::QuerySingleValue PHP Méthode

QuerySingleValue() public méthode

Executes a query and returns a single value. If more than one row is returned, only the first value in the first column is returned.
public QuerySingleValue ( string $sql ) : mixed
$sql string The query string should not end with a semicolon
Résultat mixed The value returned or FALSE if no value
    public function QuerySingleValue($sql)
    {
        $this->Query($sql);
        if ($this->RowCount() > 0 && $this->GetColumnCount() > 0) {
            $row = $this->RowArray(null, MYSQLI_NUM);
            return $row[0];
        } else {
            return false;
        }
    }

Usage Example

Exemple #1
0
}
</style>
</head>';
}
include_once 'mysql.class.php';
$db = new MySQL(true) or die('Cannot connect to MySQL server. Please check settings in mysql.class.php');
// Begin a new transaction, but this time, let's check for errors.
if (!$db->TransactionBegin()) {
    $db->Kill();
    die('Cannot start DB transactions...quitting now.');
}
// We'll create a flag to check for any errors
$success = true;
//sql building: BE CAREFUL NOT TO USE semicolon inside the sql!!!!
$sql = "SELECT MAX(uid) AS uid FROM import_hkstock;";
$result = $db->QuerySingleValue($sql);
//get the number of records
if (!$result) {
    die('Error contacting database!' . $sql);
}
$db->TruncateTable("items");
$db->TruncateTable("categories");
$db->TruncateTable("suppliers");
echo '<body>';
echo '<h1>Web Stock List</h1><br>';
echo 'Yellow= Newly enabled.<br><br>';
echo '<div id="loader">Loading...</div>';
echo '<form method="post">';
echo '<table border=0 width="100%"  cellspacing=0>';
echo '<thead>
<tr style="background:url(bar2.png) repeat-x;text-align:right" >