php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #1006 MySQL and Filereading won't work
Submitted: 1998-12-25 07:41 UTC Modified: 1998-12-25 10:24 UTC
From: Norbert dot Kuemin at gmx dot net Assigned:
Status: Closed Package: MySQL related
PHP Version: 3.0.5 OS: Linux 2.0.35
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: Norbert dot Kuemin at gmx dot net
New email:
PHP Version: OS:

 

 [1998-12-25 07:41 UTC] Norbert dot Kuemin at gmx dot net
If I do some filereadings before I access the mysql db
I get the following Warning:
Warning: 1 is not a MySQL link index in /usr/local/www/lugs/test/test.phtml on line 30

Every function for it self work perfectly.

And here the file:
<html>
<head></head>
<body>

<?
function read_file () {
  $filename = "/etc/hosts";
  if (is_readable($filename)) {
    $fp = fopen($filename, "r");
    if ($fp) {
      echo "<pre>\n";
      while (!feof($fp)) {
        $line = fgets($fp,1024);
        echo $line;
      }
      echo "</pre>\n";
    }
  } else {
    echo "<b>File $filename is not readable.</b>\n";
  }
}

function read_mysql () {
  $link_id = mysql_connect("localhost","root","");
  if (!$link_id) {
    exit;
  }
  $db_id = mysql_select_db("mysql",$link_id);
  if ($db_id) {
    $result_id = mysql_query("SELECT * FROM user",$db_id);
    if ($result_id) {
      $amount = mysql_num_rows($result_id);
      echo "Amount:$amount<p>\n";
      echo "<table border=1><tr><th>Host</th><th>User</th></tr>\n";
      for ($i=0;$i < $amount;$i++) {
        $host = mysql_result($result_id,$i,Host);
        $user = mysql_result($result_id,$i,User);
        echo "<tr><td>$host</td><td>$user</td></tr>\n";
      }
      echo "</table>\n";
    }
  }
  mysql_close($db_id);
}

read_file ();
read_mysql ();
?>
</body>
</html>

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [1998-12-25 10:24 UTC] rasmus
You are confusing $link_id and $db_id.  On line 30 you should be using $link_id instead of $db_id.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Jun 03 09:01:26 2025 UTC