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 ("
| $fields->name | "); } echo ("
|---|
| ".htmlentities($rows[$x])." | "); } echo ("