22 var
$Auto_Free = 0; ## Set to 1
for automatic mysql_free_result()
23 var
$Debug = 0;
## Set to 1 for debugging messages.
24 var
$Halt_On_Error =
"no"; ##
"yes" (
halt with message),
"no" (ignore errors quietly),
"report" (ignore errror, but spit a warning)
91 if ( 0 == $this->Link_ID ) {
94 if (!$this->Link_ID) {
95 $this->
halt(
"pconnect($Host, $User, \$Password) failed.");
99 if (!@mysql_select_db(
$Database,$this->Link_ID)) {
100 $this->
halt(
"cannot use database ".$this->Database);
107 $db_connected = @mysql_fetch_array(@mysql_query(
"SELECT DATABASE();",$this->Link_ID));
108 if ($db_connected[0] != $this->Database)
109 mysql_select_db(
$Database,$this->Link_ID);
120 @mysql_free_result($this->Query_ID);
133 global $debug_alternc;
147 # New query, discard previous result.
148 if ($this->Query_ID) {
156 $debug_chrono_start = microtime(
true);
157 $this->Query_ID = @mysql_query(
$Query_String,$this->Link_ID);
158 $debug_chrono_start = (microtime(
true) - $debug_chrono_start)*1000;
160 $this->Errno = mysql_errno();
161 $this->Error = mysql_error();
162 if( 0 != $this->Errno ){
164 throw new \Exception(
"Mysql query failed : $this->Error");
169 if (!$this->Query_ID) {
173 if (
isset($debug_alternc)) {
174 $debug_alternc->add(
"SQL Query : (".substr($debug_chrono_start,0,5).
" ms)\t $Query_String");
175 $debug_alternc->nb_sql_query++;
176 $debug_alternc->tps_sql_query += $debug_chrono_start;
179 # Will return nada if it fails. That's fine.
192 if (!$this->Query_ID) {
193 $this->
halt(
"next_record called with no query pending.");
197 $this->Record = @mysql_fetch_array($this->Query_ID);
199 $this->Errno = mysql_errno();
200 $this->Error = mysql_error();
202 $stat = is_array($this->Record);
203 if (!$stat && $this->Auto_Free) {
215 $status = @mysql_data_seek($this->Query_ID, $pos);
219 $this->
halt(
"seek($pos) failed: result has ".$this->
num_rows().
" rows");
225 @mysql_data_seek($this->Query_ID, $this->
num_rows());
226 $this->Row = $this->num_rows;
238 if (is_array($table)) {
252 $this->
halt(
"lock($table, $mode) failed.");
261 $res = @mysql_query(
"unlock tables", $this->Link_ID);
263 $this->
halt(
"unlock() failed.");
272 return @mysql_affected_rows($this->Link_ID);
276 return @mysql_num_rows($this->Query_ID);
280 return @mysql_num_fields($this->Query_ID);
293 return $this->Record[$Name];
297 print $this->Record[$Name];
301 return @mysql_insert_id($this->Link_ID);
308 if ($this->
lock($this->Seq_Table)) {
310 $q = sprintf(
"select nextid from %s where seq_name = '%s'",
313 $id = @mysql_query(
$q, $this->Link_ID);
314 $res = @mysql_fetch_array($id);
317 if (!is_array(
$res)) {
319 $q = sprintf(
"insert into %s values('%s', %s)",
323 $id = @mysql_query(
$q, $this->Link_ID);
325 $currentid =
$res[
"nextid"];
327 $nextid = $currentid + 1;
328 $q = sprintf(
"update %s set nextid = '%s' where seq_name = '%s'",
332 $id = @mysql_query(
$q, $this->Link_ID);
335 $this->
halt(
"cannot lock ".$this->Seq_Table.
" - has it been created?");
377 $id = @mysql_list_fields($this->Database, $table);
379 $this->
halt(
"Metadata query failed.");
383 $this->
halt(
"No query specified.");
386 $count = @mysql_num_fields($id);
390 for (
$i=0;
$i<$count;
$i++) {
391 $res[
$i][
"table"] = @mysql_field_table ($id,
$i);
392 $res[
$i][
"name"] = @mysql_field_name ($id,
$i);
393 $res[
$i][
"type"] = @mysql_field_type ($id,
$i);
394 $res[
$i][
"len"] = @mysql_field_len ($id,
$i);
395 $res[
$i][
"flags"] = @mysql_field_flags ($id,
$i);
398 $res[
"num_fields"]= $count;
400 for (
$i=0;
$i<$count;
$i++) {
401 $res[
$i][
"table"] = @mysql_field_table ($id,
$i);
402 $res[
$i][
"name"] = @mysql_field_name ($id,
$i);
403 $res[
$i][
"type"] = @mysql_field_type ($id,
$i);
404 $res[
$i][
"len"] = @mysql_field_len ($id,
$i);
405 $res[
$i][
"flags"] = @mysql_field_flags ($id,
$i);
411 if ($table) @mysql_free_result($id);
457 $this->Error = @mysql_error($this->Link_ID);
458 $this->Errno = @mysql_errno($this->Link_ID);
459 if ($this->Halt_On_Error ==
"no")
464 if ($this->Halt_On_Error !=
"report")
465 die(
"Session halted.");
469 printf(
"</td></tr></table><b>Database error:</b> %s<br />\n", $msg);
470 printf(
"<b>MySQL Error</b>: %s (%s)<br />\n",
476 $this->
query(
"SHOW TABLES");
478 while (
$info=mysql_fetch_row($this->Query_ID))
480 $return[
$i][
"table_name"]=
$info[0];