[英]Read columns in php with mysqli_query doesn't work
So I'm trying to read from an SQL file where I have a table: 所以我试图从我有一个表的SQL文件中读取:
CREATE TABLE IF NOT EXISTS `tariff` (
`type` varchar(50) NOT NULL DEFAULT '',
`price_single` varchar(30) NOT NULL DEFAULT '0',
`price_double` varchar(30) NOT NULL DEFAULT '0',
`totalroom` int(3) NOT NULL DEFAULT '0',
primary key(`type`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
and I inserted: 我插入了:
INSERT INTO `tariff` (`type`, `price_single`, `price_double`, `totalroom`) VALUES
('Standard', '2600', '3100', 100),
('Deluxe', '3100', '4200', 50),
('Super Deluxe', '3800', '4600', 15);
next I have : 接下来我有:
<?php
$server = "localhost";
$unm = "root";
$pwd = "root";
$db = "hotel";
$con = mysqli_connect($server, $unm, $pwd, $db);
$qrysel = "select * from tariff";
$rs = mysqli_query($con, $qrysel);
if (!$rs) {
echo "here it stops";
die($qrysel);
}
while ($v = mysqli_fetch_array($rs)) {
echo "<tr>";
echo "<td>".$v['type']."</td>";
echo "<td>".$v[1]."</td>";
echo "<td>".$v[2]."</td>";
echo "<td>".$v[3]."</td>";
echo "</tr>";
}
echo "</table>";
?>
I don't know where is the problem. 我不知道问题出在哪里。 I'm trying to output what I have done in the insert in the SQL file but it goes into the if-statement and there it stops. 我正在尝试输出我在SQL文件的插入中完成的操作,但是它进入了if语句,并在那里停止了。
Your Query looks just fine what i assume is there is an error while connecting to database you should first do some error handling to see whether it is connecting to the database or not here's a solution for error handling in db connectivity 您的查询看起来很好,我假设连接到数据库时出现错误,您应该首先进行一些错误处理,以查看它是否正在连接到数据库,这是数据库连接中错误处理的解决方案
$server="localhost";
$unm="root";
$pwd="root";
$db="hotel";
$con=mysqli_connect($server,$unm,$pwd,$db);
if (!$con){
die('Could not connect: ' . mysqli_connect_error($con));
}
if there is a database error i recommend using the following credentials 如果有数据库错误,我建议使用以下凭据
$server="localhost";
$unm="root";
$pwd="";
$db="hotel";
$con=mysqli_connect($server,$unm,$pwd,$db);
if (!$con){
die('Could not connect: ' . mysqli_connect_error($con));
}
First try to check the connection: 首先尝试检查连接:
if (mysqli_connect_errno()) {
printf("Error: %s\n", mysqli_connect_error());
exit();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.