【问题标题】:mysql_connect is not working how to fix with mysql [duplicate]mysql_connect 不工作如何用 mysql 修复 [重复]
【发布时间】:2019-05-22 03:13:58
【问题描述】:

mysql_connect 不工作,我不知道如何用 mysqli 修复它。

我尝试将我的 PHP 版本从 PHP 7 降级到 5,但我也失败了

这是我的代码:

<?php

$query1=mysql_connect("localhost","root","");


mysql_select_db("edgedata",$query1);


$start=0;

$limit=8;


if(isset($_GET['id']))


{`
    $id=$_GET['id'];

    $start=($id-1)*$limit;
}

$query=mysql_query("select * from items LIMIT $start, $limit");

while($query2=mysql_query_fetch_array($query))
{

【问题讨论】:

  • not working 是什么意思?有什么错误吗?
  • 另外,大多数情况下,将mysql_* 替换为mysqli_* 会起作用
  • @catcon 不会,大多数函数的用法都发生了变化。他们需要连接字符串
  • @user3783243:是的,忘了说。
  • 不要降级。那是走错路了。使用手册并了解如何使用这些功能......或使用 PDO。您当前的使用也对 SQL 注入开放。

标签: php mysql


【解决方案1】:

我解释了如何在连接中设置mysqli。

  $con=new mysqli("localhost","root","","edgedata");
   $start=0;
   $limit=8;
   if(isset($_GET['id']))
   {
    $id=$_GET['id'];

     $start=($id-1)*$limit;

    }
     $query=mysqli_query($con,"select * from items LIMIT $start, $limit");
       while($query2=mysqli_fetch_array($query)) {

【讨论】:

  • 非常感谢...我尝试了您的代码并且程序运行了 100%,尽管它在某处向我显示此错误消息“在这行代码中调用未定义函数 mysql_num_row”$rows= mysql_num_rows(mysql_query("select * from items")); $total=ceil($rows/$limit)
  • 你当然可以先将 mysql_num_rows 更改为 mysqli_num_row。
  • 欢迎亚历克斯 :)
猜你喜欢
  • 2017-10-25
  • 2014-03-14
  • 2018-11-22
  • 2016-04-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-04-11
  • 2016-06-18
相关资源
最近更新 更多