printerror=true; } } /*## #### Call then connect("mysqlhost","mysqluser","mysqlpasswd","name of mysql database") #### it returns some public $con or creates errors; ##*/ function connect($host=false, $user=false, $pass=false, $dbname=false) { $con=@mysql_connect($host, $user, $pass); if (!$con) { $this->makeerror(); return false; } $this->con=$con; $db=@mysql_select_db($dbname, $con); if (!$db) { $this->makeerror(); return false; } return $this->con; } /*## #### Call speak("SQL STRING") to send some sql query to the database; #### it returns some public $sql_id, or creates errors; ##*/ function speak($sql=false) { if (!$this->con) { $this->error_id=$this->msg1; $this->makeerror(); return false; } if ($this->sql_id) { @mysql_free_result($this->sql_id); } $sql_id=mysql_query($sql, $this->con); $this->sql_id=$sql_id; return $this->sql_id; } /*## #### Call listen() to get the result of the query; #### it returns an array with the results of the query, or creates errors; #### listen() must be called after speak("SQL STRING") was called; ##*/ function listen() { if (!$this->con) { $this->error_id=$this->msg1; $this->makeerror(); return false; } if (!$this->sql_id) { $this->error_id=$this->msg2; $this->makeerror(); return false; } $data=mysql_fetch_array($this->sql_id, MYSQL_BOTH); $this->rows=mysql_num_rows($this->sql_id); $this->fields=mysql_num_fields($this->sql_id); return $data; } /*## #### Call onscreen("SQL STRING") to print a table with the result of the query; ##*/ function onscreen($sql=false) { $this->speak($sql); echo (""); while ($fields=@mysql_fetch_field($this->sql_id)) { echo (""); } echo ("\n"); while ($rows = $this->listen()) { echo (""); for ($x=0; $x<@mysql_num_fields($this->sql_id); $x++) { echo (""); } echo ("\n"); } echo ("
$fields->name
".htmlentities($rows[$x])."
"); } /*## #### Function makeerror() is called whenever some error has occured; #### If there is any error_id, it returns the user specified messages $msg1, $msg2, #### else it returns the mysql error number and message; #### If $printerror is true, the error message will be printed in the main script; ##*/ function makeerror() { if (!$this->error_id) { if (mysql_errno()){ $result="" .mysql_errno(). " :" . mysql_error(). "
"; $this->errors=$result; if ($this->printerror){ echo $result; } return $result; exit; } } else { $result="$this->error_id
"; $this->errors=$result; if ($this->printerror){ echo $result; } return $result; } } } ?>