您好我正在尝试查询数据库并将值返回给客户端。所以这是我的代码有两个功能。该速率应该在db中得到速率。
public function connect($description){
//creating connection
$con = new mysqli('localhost','root','','ci_vetro');
//mysql_connect('localhost','root','') or die("Connection Error: ".mysql_error());
//mysql_select_db('ci_vetro');
//check connection
if($con->connect_error):
die('Connection Error: '. $con->connect_error);
endif;
$sql= "SELECT * from. exchange_rates where description=.'$description'.";
$result= $con->query($sql);
if($result->num_rows > 0):
while($row = $result->fetch_assoc()) :
$rate=$row["rate"]. "<br>";
endwhile;
else:
echo "0";
endif;
$con->close();
return $rate;
}
public function getCurrency($currency) {
$rate=connect($currency);
switch ($currency){
case 'USD':
return int($rate);
break;
default:
return 0;
break;
}
}