Php 正在尝试从第一行检索特定列
我正在尝试从Php 正在尝试从第一行检索特定列,php,mysql,Php,Mysql,我正在尝试从MainPage列的第一行检索数据。 以下是我使用的代码: $con=mysqli_connect("localhost","---","---","---"); // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } $result = mysql_query($con,"SELECT conca
MainPage
列的第一行检索数据。
以下是我使用的代码:
$con=mysqli_connect("localhost","---","---","---");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysql_query($con,"SELECT concat (MainPage) from content");
$row = mysql_fetch_row($result);
echo $row[0];
mysqli_close($con);
以下是我收到的错误:
警告:mysql_query():提供的参数不是有效的mysql链接
资源在。。。第17行
知道为什么吗?
谢谢
$con
是第二个参数
您也在使用mysqli\u connect
,但是mysql\u query
。您应该使用mysqli\u query您可以通过以下方式订购:
$result=mysql\u query($con),从内容中选择concat(主页)
按主页限制订购1
”
如果它是一个大的数据集,你可能想考虑在主页上添加索引。
< P>你在MySQL和MySQL之间混合。 试试这个 concat(主页)将永远无法使用您所关注的主页?resource mysql_query ( string $query [, resource $link_identifier = NULL ] )
$result = mysqli_query($con,"SELECT concat(MainPage) as mainp from content");
$row = mysqli_fetch_array($result);
echo $row['mainp'];