PHP Classes

Recursuve function don't work

Recommend this page to a friend!

      Ultimate MySQL  >  All threads  >  Recursuve function don't work  >  (Un) Subscribe thread alerts  
Subject:Recursuve function don't work
Summary:recursive function overwrites results
Messages:4
Author:Sergeant
Date:2009-06-15 12:26:36
Update:2012-02-26 08:26:47
 

  1. Recursuve function don't work   Reply   Report abuse  
Picture of Sergeant Sergeant - 2009-06-15 12:26:36
When doing a recursive function with the mysql class, it does not work, it simply overwrites the results from the earlier function instance, i had to go back to the good old, mysql_query function from php, which works fine.

  2. Re: Recursuve function don't work   Reply   Report abuse  
Picture of roger kenlly gonzales roger kenlly gonzales - 2011-09-06 22:51:13 - In reply to message 1 from Sergeant
I HAVE A PROBLEMA: THIS IS MY CODE.

<?php
require_once 'mysql.class.php';
$db = new MySQL(true);

function insertar() {
$db2 = new MySQL(true);
if ( $db2->Error() ) $db2->Kill;
else {
$query = $db2->Query("select * from user");
if ( !$query ) $db2->Kill();
else {
return $db2->RowCount();
}
}
}

if ( insertar() > 0 ) {

$field['nombre'] = MySQL::SQLValue("Roger", MySQL::SQLVALUE_TEXT);
$result = $db->InsertRow('user', $field);
if ( !$result ) $db->Kill();
else echo $db->GetLastInsertID();
} else $db->Kill();
$db->Close();
?>

my table database:

CREATE TABLE `user` (

`id` int(11) NOT NULL AUTO_INCREMENT,

`nombre` varchar(45) NOT NULL,

PRIMARY KEY (`id`)

) ENGINE=InnoDB DEFAULT CHARSET=utf8


But, when I make a transaction within the mysql function with the ultimate class, the class did not work.

  3. Re: Recursuve function don't work   Reply   Report abuse  
Picture of roger kenlly gonzales roger kenlly gonzales - 2011-09-06 22:52:07 - In reply to message 1 from Sergeant
I HAVE A PROBLEMA: THIS IS MY CODE.

<?php
require_once 'mysql.class.php';
$db = new MySQL(true);

function insertar() {
$db2 = new MySQL(true);
if ( $db2->Error() ) $db2->Kill;
else {
$query = $db2->Query("select * from user");
if ( !$query ) $db2->Kill();
else {
return $db2->RowCount();
}
}
}

if ( insertar() > 0 ) {

$field['nombre'] = MySQL::SQLValue("Roger", MySQL::SQLVALUE_TEXT);
$result = $db->InsertRow('user', $field);
if ( !$result ) $db->Kill();
else echo $db->GetLastInsertID();
} else $db->Kill();
$db->Close();
?>

my table database:

CREATE TABLE `user` (

`id` int(11) NOT NULL AUTO_INCREMENT,

`nombre` varchar(45) NOT NULL,

PRIMARY KEY (`id`)

) ENGINE=InnoDB DEFAULT CHARSET=utf8


But, when I make a transaction within the mysql function with the ultimate class, the class did not work.

  4. Re: Recursuve function don't work   Reply   Report abuse  
Picture of Brian Brian - 2012-02-26 08:26:47 - In reply to message 1 from Sergeant
Cos it needs to be released or closed like this $db->Release(); or $db->Close();

For "mysql_connect", the link to the server will be closed as soon as the execution of the script ends, unless it's closed earlier by explicitly calling mysql_close().

refer to: http://php.net/manual/en/function.mysql-connect.php