Re: [PHP-DB] Mysql-class

2002-01-21 Thread Jason Wong

On Tuesday 22 January 2002 22:35, Johannes Hiemer wrote:

First of all, please keep the discussion on the list!

> >What did you want it to do?
>
> I want it to do things like inserting into Mysql-dbs
> Fetching arrays. Just every Mysql-command which
> Is also suported in PHP.
> What is it doing now?
> It is doing nothing if I create a class of it.
> If I create a  class using the fetch_array function
> And echoing it after it just says: Object.
> What error does it give, if any?
> S. a.

Looking back at your code:

>  $test = new get_db();
>  $test -> connect();
>  $test -> db_query("SELECT * FROM topics");
>  $test -> fetch_array("SELECT * FROM topics");
>  echo "$test";


You should be using:

  $test->connect();

etc (note there are no spaces surrounding the "->").

BTW, I'm not trying to put you off, but why are you writing your own class of 
mysql db functions? There are already loads out there which are tested (and 
working!). If this is an exercise in learning how to write classes then good 
luck :)


-- 
Jason Wong -> Gremlins Associates -> www.gremlins.com.hk

/*
The perfect lover is one who turns into a pizza at 4:00 A.M.
-- Charles Pierce
*/

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP-DB] Mysql-class

2002-01-20 Thread Jason Wong

On Monday 21 January 2002 21:52, Johannes Hiemer wrote:
> Hi,
> i coded a Mysql-Class, there are no compiling-errors when i run it.
> But the problem is that it doesn´t do what i want it to do.
> I added the sourcecode below and would be happy for any sugestions
> how to make it better.

[snip]

What did you want it to do? 

What is it doing now? 

What error does it give, if any?


-- 
Jason Wong -> Gremlins Associates -> www.gremlins.com.hk

/*
Always there remain portions of our heart into which no one is able to enter,
invite them as we may.
*/

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP-DB] Mysql-class

2002-01-20 Thread Johannes Hiemer

Hi,
i coded a Mysql-Class, there are no compiling-errors when i run it.
But the problem is that it doesn´t do what i want it to do.
I added the sourcecode below and would be happy for any sugestions
how to make it better.

Cu Johannes Hiemer

Code:
islinked) {

 if($password == "") {

 if($use_pconnect == 0) {
 $this->link_id = mysql_pconnect($this->server,
$this->user);
 }
 else {
$this->link_id = mysql_connect($this->server, $this->user,
$this->password);
 }
 }
 else  {
 if($use_pconnect == 1) {
 $this->link_id = mysql_pconnect($this->server,
$this->user);
 }
 else {
 $this->link_id = mysql_connect($this->server,
$this->user, $this->password);
 }
 }
 }

 if(!$this->link_id) {

 $this->stopm("Couldn´t connect to: ".$this->server.
 " with ".$this->user."".mysql_error."reason");
 }

 if(!$this->database == "") {
 $this->db_query = mysql_db_query($this->database,
$this->link_id);
 $this->stopm("Couldn´t connect to".$this->database);
 }

}
function error() {
$this->error = mysql_error();
return $this->error;
}

function errno() {
$this->errno = mysql_errno();
return $this->errno;
}

function reporterrno() {


$this->errno = mysql_errno();
$this->file = "db_logs.txt";

if(file_exists($this->file)) {
$this->openlogfile = fopen($this->file, "a+");

 if(feof($this->openlogfile)) {
fputs($this->openlogfile, date("d.M.Y h:m:s",
time())."".$REMOTE_ADDR."\n".$this->errno);
fclose($this->openlogfile);
}
}
else {
$this->openlogfile = fopen($this->file,"a+");

if(feof($this->openlogfile)) {
fputs($this->openlogfile, date("d.M.Y h:m:s",
time()).",".$REMOTE_ADDR."n");
fclose($this->openlogfile);
}
@mail("[EMAIL PROTECTED]", 'Mysql_error: ".$this->errno."',
date("d.M.Y h:m:s", time()).",".$REMOTE_ADDR."\n".$this->errno."");

}
  }
function db_select($database) {

$this->database = $database;
$this->db_query = mysql_select_db($this->database, $this->link_id);
$this->stopm("Couldn´t connect
to".$this-database."reason".$this->error);

}

function db_query($string_query) {

$this->query = mysql_query($string_query, $this->link_id);

if(!$this->query) {
$this->stopm("Invalid Mysql_query: ".$string_query);
}

return $this->query;

}

function fetch_array($string_query) {

if (isset($query_string)) {
if(!empty($string_query)) {
$this->stopm("Query was emtpy or wrong".$this->error);
}

   $this->fetch_data = mysql_fetch_array($this->query, $this->link_id);

if(!$this->fetch_data) {
$this->stopm("Query was emtpy or wrong".$this->error);
}
else {

return $this->fetch_data;
}
}
   }

function stopm($msg) {
$this->error=mysql_error();
$this->errno=mysql_errno();


if ($this->reporterror == 1) {
  $message="Database error in $this->appname: $msg\n";
  $message.="mysql error: $this->error\n";
  $message.="mysql error number: $this->errno\n";
  $message.="Date: ".date("l dS of F Y h:i:s A")."\n";
  $message.="Script: ".getenv("REQUEST_URI")."\n";
  $message.="Referer: ".getenv("HTTP_REFERER")."\n";

  @mail("[EMAIL PROTECTED]", 'Mysql_error: ".$this->errno."',
date("d.M.Y h:m:s", time()).",".$REMOTE_ADDR."\n".$this->errno."");

  echo "\n\n";

  echo "\nEs sind Probleme mit der Datenbank
aufgetreten.\n";
  echo "Versuchen sie es erneut in dem sie den Refresh Button des
Browser nutzen.";
  echo "Es wurde eine Email an unseren Techniker gesendetmailto:$technicalemail\";>Techniker, der mit diesem Link
kontaktiert werden kann, sofern der Fehler erneut auftritt.";
  echo "Wir bitten vielmals um Entschuldigung.";
  die("");
   }
}
  }

  $test = new get_db();
  $test -> connect();
  $test -> db_query("SELECT * FROM topics");
  $test -> fetch_array("SELECT * FROM topics");
  echo "$test";

?>



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]