|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[1999-05-22 20:58 UTC] lts at itprotect dot de
Today I found a tricky bug or problem. I used the class functionality to construct a basic class for the database
connection from php 3.0.8 to a mySQL 3.21.22 database.
The php3 / html code show the problem:
<pre>
<HTML>
<HEAD>
<TITLE> User List </TITLE>
</HEAD>
<!---- Database
create database diplom;
create table user (
id INT not null auto_increment,
primary key(id),
account CHAR(30) not null,
);
--->
<Body>
<?
class dbmySQL
{
var $conn = 0;
var $db = "";
function dbLogon( $name, $pw, $host )
{
if($this -> conn != 0)
return true;
$this -> conn = mysql_pconnect($host, $name,$pw) or die("Unable to connect to SQL server");
if( $this -> conn == false )
return false;
return true;
}
function dbOpen( $db )
{
$this -> db = $db;
mysql_select_db($db) or die("Unable to select database");
if( $this -> conn == false )
{
return 0;
}
$dbCurs = new dbCursor;
if( $dbCurs == 0 )
return 0;
return $dbCurs;
}
function dbQuery( $dbCurs, $query )
{
mysql_select_db($this -> db) or die("Unable to select database");
$result = mysql_query($query, $this -> conn);
$dbCurs -> SetResult( $result );
// here everything is ok, we got the num of rows
echo $dbCurs -> dbGetRows();
// after we leave this object function, it seems that the variable was destroyed
return true;
}
function dbLogoff( )
{
mysql_close( $this -> conn );
$this -> conn = 0;
return true;
}
}
class dbCursor
{
var $result;
function SetResult( $result )
{
$this -> result = $result;
}
function dbFetchInto( )
{
$arr = mysql_fetch_row( $this -> result );
return $arr;
}
function dbGetRows( )
{
return mysql_num_rows( $this -> result );
}
function dbFreeCursor( )
{
mysql_free_result($this -> result);
return( true );
}
}
$dbObj = new dbmySQL;
if($dbObj -> dbLogon( "web", "", "localhost" ) == false)
echo "No db connect possible";
$dbCurs = $dbObj -> dbOpen( "diplom" );
$dbObj -> dbQuery( $dbCurs, "SELECT account from user");
// here everything goes wrong - it looks like the result string was killed
$dbCurs -> dbGetRows( );
$dbCurs -> dbFreeCursor( );
$dbObj -> dbLogoff( );
?>
</BODY>
</HTML>
</pre>
I hope, the bug can be fixed. It is a terrible bug! Compiled was the complete tree with apache 1.3.3, PHP3.0.8 and mySQL 3.21.22. The same problem was with PHP3.0.7.
Regards,
Th. Sudmann
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Dec 22 15:00:01 2025 UTC |
Change the declaration from function dbQuery( $dbCurs, $query ) to function dbQuery( &$dbCurs, $query ) Otherwise, dbQuery will only operate on a *copy* of dbCurs.