Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 无法通过php代码连接到mysql数据库,php致命错误:Class';MySQLi';在中找不到_Linux_Mysqli_Xampp - Fatal编程技术网

Linux 无法通过php代码连接到mysql数据库,php致命错误:Class';MySQLi';在中找不到

Linux 无法通过php代码连接到mysql数据库,php致命错误:Class';MySQLi';在中找不到,linux,mysqli,xampp,Linux,Mysqli,Xampp,我正在linux上使用Xampp(Xampp-linux-x64-7.0.13-0)。我无法通过php代码连接到mysql数据库。我得到错误php致命错误:在第3行的/opt/lampp/htdocs/test5/connection.php中找不到类“MySQLi”。 代码如下: <?php // sqltest.php require_once 'login5.php'; $conn = new \MySQLi($hn, $un, $pw, $db); if ($conn-&

我正在linux上使用Xampp(Xampp-linux-x64-7.0.13-0)。我无法通过php代码连接到mysql数据库。我得到错误php致命错误:在第3行的/opt/lampp/htdocs/test5/connection.php中找不到类“MySQLi”。 代码如下:

<?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]);
   }
 ?>

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