我尝试使用 intval 将我的字符串数组转换为 INT 但是结果/返回总是int(1) 而数据库值为 14698
我的数据库:
+-------+---------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+---------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| curr | char(3) | NO | | NULL | |
| rate | int(11) | NO | | 0 | |
+-------+---------+------+-----+---------+----------------+
+----+------+-------+
| id | curr | rate |
+----+------+-------+
| 1 | USD | 1 |
| 2 | IDR | 14698 |
| 3 | JPY | 112 |
| 4 | EUR | 1 |
| 5 | THB | 33 |
+----+------+-------+
这是我的 crudQuery.php 页面:
<?php
require 'config.php';
if (isset($_POST['save'])) {
require_once 'functions.php';
$qty = $_POST['qty'];
$qty = (int) $qty;
$curr = $_POST['curr'];
$price = $_POST['price'];
$price = (int) $price;
$rate = queryInt("SELECT rate FROM rate_master WHERE curr = '$curr'");
var_dump($rate);echo $rate[0];
这是我的functions.php页面:
<?php
require 'config.php';
function queryInt($query) {
global $conn;
$result = mysqli_query($conn, $query);
$rows = [];
while ($row = mysqli_fetch_assoc($result)) {
$rows [] = intval($row);
}
return $rows;
}
然后, var_dump 的结果是:
array(1) { [0]=> int(1) } 1
我应该做什么,以便从数据库中返回值而不是 1 ?
月关宝盒