【问题标题】:not able to connect to mysql database through php code , PHP Fatal error: Class 'MySQLi' not found in无法通过php代码连接到mysql数据库,PHP致命错误:找不到类'MySQLi'
【发布时间】:2017-05-04 06:42:20
【问题描述】:

我在 Linux 上使用 Xampp (xampp-linux-x64-7.0.13-0)。我无法通过 php 代码连接到 mysql 数据库。我收到错误 PHP Fatal error: Class 'MySQLi' not found in /opt/lampp/htdocs/test5/connection.php 第 3 行。 这是代码:

<?php // sqltest.php
  require_once 'login5.php';
  $conn = new \MySQLi($hn, $un, $pw, $db);
 if ($conn->connect_error) die($conn->connect_error);

 if (isset($_POST['delete']) && isset($_POST['isbn']))
{
$isbn   = get_post($conn, 'isbn');
$query  = "DELETE FROM classics WHERE isbn='$isbn'";
$result = $conn->query($query);
if (!$result) echo "DELETE failed: $query<br>" .
  $conn->error . "<br><br>";
}

if (isset($_POST['author'])   &&
  isset($_POST['title'])    &&
  isset($_POST['category']) &&
  isset($_POST['year'])     &&
  isset($_POST['isbn']))
{
$author   = get_post($conn, 'author');
$title    = get_post($conn, 'title');
$category = get_post($conn, 'category');
$year     = get_post($conn, 'year');
$isbn     = get_post($conn, 'isbn');
$query    = "INSERT INTO classics VALUES" .
  "('$author', '$title', '$category', '$year', '$isbn')";
$result   = $conn->query($query);

if (!$result) echo "INSERT failed: $query<br>" .
  $conn->error . "<br><br>";
}

echo <<<_END
<form action="sqltest.php" method="post"><pre>
  Author <input type="text" name="author">
 Title <input type="text" name="title">
 Category <input type="text" name="category">
  Year <input type="text" name="year">
  ISBN <input type="text" name="isbn">
       <input type="submit" value="ADD RECORD">
 </pre></form>
 _END;

  $query  = "SELECT * FROM classics";
  $result = $conn->query($query);
  if (!$result) die ("Database access failed: " . $conn->error);

  $rows = $result->num_rows;

  for ($j = 0 ; $j < $rows ; ++$j)
 {
   $result->data_seek($j);
   $row = $result->fetch_array(MYSQLI_NUM);

   echo <<<_END
   <pre>
   Author $row[0]
   Title $row[1]
   Category $row[2]
   Year $row[3]
   ISBN $row[4]
   </pre>
  <form action="sqltest.php" method="post">
   <input type="hidden" name="delete" value="yes">
   <input type="hidden" name="isbn" value="$row[4]">
   <input type="submit" value="DELETE RECORD"></form>
   _END;
   }

   $result->close();
   $conn->close();

   function get_post($conn, $var)
   {
     return $conn->real_escape_string($_POST[$var]);
   }
 ?>

我在这一步上做得很糟糕,我删除了 extension=php_mysql.dll 前面的分号 扩展=php_mysqli.dll 在 php.ini 中 但没有用。 如果有人有解决方案,请帮助我。

【问题讨论】:

    标签: linux mysqli xampp


    【解决方案1】:

    我的 php.ini 文件中没有错误。整个罪魁祸首是我的 IDE(eclips)。我的 php 可执行文件的路径不准确,这就是为什么“PHP 致命错误:找不到类 'MySQLi'”的原因。当我将我的 php 可执行文件的路径更改为 /opt/lampp/bin/php 时,错误被删除。 感谢大家的回复和支持。

    【讨论】:

      猜你喜欢
      • 2014-12-16
      • 2012-12-29
      • 1970-01-01
      • 2023-03-11
      • 1970-01-01
      • 1970-01-01
      • 2017-02-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多