|
Comments for: peter20001107
| Message # 1013725: |
|
Date: 10/10/02 10:58
By: onez Subject: 2 or more Level of Queries Solns? I slightly changed the codes to allow making one or more queries while the last query haven't yet been freed. (mainly because I had developed another class used its Internal QID) I used an array to store the QueryID returned by php, & default using the index QID=0 to access.(which hopefully backward compatabile of the old codes) class DB_SQL { var $Host = ""; // Hostname of our MySQL server. var $Database = ""; // Logical database name on that server. var $User = ""; // User und Password for login. var $Password = ""; var $Link_ID = 0; // Result of mysql_connect(). var $Query_ID = array(); // Array of the Result of mysql_query(). var $Record = array(); // current mysql_fetch_array()-result. var $Row = array(); // Array of current row number of corresponding Query_ID. var $Errno = 0; // error state of query... var $Error = ""; var $INTERNAL = 5; // internal query ID // DB_Sql constructor function DB_Sql ($TheHost, $TheDatabase, $TheUser, $ThePassword) { $this->Host = $TheHost; $this->Database = $TheDatabase; $this->User = $TheUser; $this->Password = $ThePassword; } function halt($msg){ printf("</td></tr></table><b>Database error:</b> %s<br>\n", $msg); printf("<b>MySQL Error</b>: %s (%s)<br>\n", $this->Errno, $this->Error); die("Session halted."); } function connect() { if ( 0 == $this->Link_ID ) { $this->Link_ID=mysql_connect($this->Host, $this->User, $this->Password); if (!$this->Link_ID) { $this->halt("Link-ID == false, connect failed"); } if (!mysql_query(sprintf("use %s",$this->Database),$this->Link_ID)) { $this->halt("cannot use database ".$this->Database); } } } function query( $Query_String, $QID=0 ) { $this->connect(); $this->Query_ID[ $QID ] = mysql_query($Query_String,$this->Link_ID); $this->Row[ $QID ] = 0; $this->Errno = mysql_errno(); $this->Error = mysql_error(); if (!$this->Query_ID[ $QID ]) { $this->halt("Invalid SQL: ".$Query_String); } return $this->Query_ID[ $QID ]; } // The next_record() function can be used to retrieve the query result. The function reads the current result row, increments the row counter and checks for errors function next_record( $QID=0 ) { $this->Record[ $QID ] = mysql_fetch_array($this->Query_ID[ $QID ]); $this->Row[ $QID ] += 1; $this->Errno = mysql_errno(); $this->Error = mysql_error(); $stat = is_array($this->Record[ $QID ]); if (!$stat) { mysql_free_result($this->Query_ID[ $QID ]); $this->Query_ID[ $QID ] = 0; } return $stat; } function current_record( $QID=0 ){ return $this->Record[ $QID ]; } // Using seek() you may move within the current result set and read a single result multiple times (unless it has been freed) or skip certain records at the beginning of the result set function seek($pos, $QID=0 ) { $status = mysql_data_seek($this->Query_ID[ $QID ], $pos); if ($status) $this->Row[ $QID ] = $pos; return; } function current_row( $QID=0 ){ return $this->Row[ $QID ]; } // num_rows() and num_fields() return the width and height of the result set function num_rows( $QID=0 ) { return mysql_num_rows($this->Query_ID[ $QID ]); } function num_fields( $QID=0 ) { return mysql_num_fields($this->Query_ID[ $QID ]); } // Access Single Result function get($Name, $QID=0) { return $this->Record[$QID][$Name]; } function echo_Record($Name, $QID=0) { echo $this->Record[$QID][$Name]; } /** * test the success of SQL insert or update statments * */ function affected_rows() { return @mysql_affected_rows($this->Link_ID); } // Check whether record exists in Specifc Table function isExists( $szTableName, $szCondition ){ $query = "Select Count(*) > 0 As boolean From $szTableName Where $szCondition"; $this->query( $query, $this->INTERNAL ); $this->next_record( $this->INTERNAL ); return $this->get( "boolean", $this->INTERNAL ) ; } } |
Previous Message | Next Message |
| Comments: | ||
| RE: PHP Server | Kanta | 02/11/05 04:03 |
| RE: Play movie at web site with PHP | dinesh | 12/11/04 03:29 |
| PHP Server | lid | 10/16/02 12:09 |
| 2 or more Level of Queries Solns? | onez | 10/10/02 10:58 |
| sql server &PHP | ali alinia | 09/11/02 05:47 |
| where can i get PHPLIB? | Alex | 07/26/02 21:33 |
| Help Mysql_fecth_row undefined | Ronal Y | 07/18/02 02:26 |
| RE: Play movie at web site with PHP | Spacecat | 07/09/02 03:05 |
| How to hook up the database to the site? | David | 07/05/02 23:56 |
| myconnect() function not working | Salim Pinjar | 06/20/02 08:46 |
| Play movie at web site with PHP | Danny | 05/06/02 08:58 |
| Help me! | ldvhai | 04/24/02 23:56 |
| sql server | Hatem Gamal | 03/25/02 10:14 |
| help me pls.... | zabehry | 03/23/02 01:37 |
| RE: PHP with Oracle | yoke | 02/22/02 23:09 |
| Checkbox to DB | steque | 02/04/02 09:06 |
| TEST!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | Sheep | 01/21/02 21:48 |
| RE: PHP & Interbase | Surojit Niyogi | 11/06/01 12:19 |
| PHP & Interbase | Maxi | 10/26/01 13:26 |
| Where can I get PHPLIB? | Zenons | 10/19/01 06:20 |
| globals $db_connect, $db_database | Michael Assink | 09/20/01 18:43 |
| RE: PHP with Oracle | Hassan | 08/27/01 06:11 |
| RE: Hellllppppp! | K Black | 08/11/01 18:03 |
| help me !!! | danilo | 07/03/01 11:43 |
| PHPLIB with PHP4 | Ricardo Matos | 06/07/01 13:27 |
| RE: PHP with Oracle | Rach | 05/31/01 01:34 |
| RE: PHP with Oracle | Rach | 05/31/01 01:25 |
| RE: All Bad Ideas | Gold | 05/17/01 18:55 |
| Do I need *.dll | ceria | 03/27/01 19:52 |
| RE: .inc files, bad idea | dsh | 02/11/01 17:43 |
| RE: PHP with Oracle | raj | 02/05/01 15:03 |
| hello newbie here. | frederick | 02/04/01 19:23 |
| How can I log on a persistant oracle connect | Richard Schottdorf | 01/09/01 11:01 |
| RE: PHP with Oracle | Joerg Behrens | 12/19/00 14:20 |
| Utilisation de php4 avec paradox | Zarambaud | 12/18/00 04:29 |
| RE: Why not just use ADODB -- its simpler? | Nikolai Steenstrup | 12/11/00 21:20 |
| RE: Sybase connection problem? | Joeri Cornelissens | 12/11/00 09:28 |
| Hellllppppp! | Carrie | 12/10/00 05:17 |
| PHP Data Synchronization | girish | 12/05/00 01:42 |
| RE: conversion of outer join in oracle to postgre | Tom Anderson | 11/29/00 18:02 |
| RE: All Bad Ideas | aris | 11/28/00 03:05 |
| RE: Why not just use OOP? | Robert Campbell | 11/17/00 08:30 |
| RE: .inc files, bad idea | Jan Lehnardt | 11/13/00 16:27 |
| RE: extends OOPs? | Peter Moulding | 11/13/00 14:28 |
| .inc files, bad idea | Josh Duncan | 11/13/00 13:33 |
| PHP with Oracle | Hareshkumar Khandal | 11/12/00 23:59 |
| RE: OOPs? | Ying Zhang | 11/12/00 03:27 |
| conversion of outer join in oracle to postgre | Atul Vaze | 11/11/00 06:14 |
| OOPs? | Peter Moulding | 11/10/00 18:46 |
| RE: Disappointed | Rex Byrns | 11/10/00 09:50 |
| RE: Disappointed | Tim Perdue, PHPBuilder.com | 11/09/00 12:08 |
| RE: Disappointed | Tom Anderson | 11/09/00 11:32 |
| Disappointed | Tim Perdue, PHPBuilder.com | 11/09/00 10:41 |
| RE: All Bad Ideas | John Lim | 11/09/00 09:22 |
| RE: Why not just use ADODB -- its simpler? | John Lim | 11/09/00 09:06 |
| Great LIB, I'm it's power user! :-) | Ahmad Anvari | 11/08/00 15:00 |
| RE: Why not just use ADO-DB? | Tom Anderson | 11/08/00 13:50 |
| RE: extend classes, not rewrite code | Joe Link | 11/08/00 13:12 |
| Why not just use ADO-DB? | Lucien Ceder | 11/08/00 12:23 |
| All Bad Ideas | Tom Anderson | 11/08/00 11:12 |
| extend classes, not rewrite code | Donncha O Caoimh | 11/08/00 08:13 |
| Sybase connection problem? | Toni Tunkkari | 11/08/00 02:26 |
| Why not just use OOP? | Willo van der Merwe | 11/08/00 02:05 |
|
If you are looking for help, please post on the appropriate forum here. Your questions will be answered much more quickly. | ||


