CodeCharge Studio
search Register Login  

Web Reports

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> PHP

 How to pick-up return code from Mysql DB and PHP

Print topic Send  topic

Author Message
rado

Posts: 221
Posted: 04/22/2009, 8:20 AM

Hi,
I would like to make a table (audit_events) in MySQl database which will record what was the status of each called function in the project. For example if user click on register button, I would like to update table with event_id, user_id,date_time and return_code.
How I can capture return code of DataBase that will tell me that transaction was succesfull or not. Same think with execution of PHP.
How I can accomplishe this using CCS4
Is there any example that I can use for this case?

Thanks for help.

Rado
View profile  Send private message
aondecker

Posts: 58
Posted: 04/22/2009, 8:40 AM

Quote rado:
Hi,
I would like to make a table (audit_events) in MySQl database which will record what was the status of each called function in the project. For example if user click on register button, I would like to update table with event_id, user_id,date_time and return_code.
How I can capture return code of DataBase that will tell me that transaction was succesfull or not. Same think with execution of PHP.
How I can accomplishe this using CCS4
Is there any example that I can use for this case?

Thanks for help.

Rado


in your after update/ after insert events you can retrieve the last inserted/updated record and do it that way.

example. Let's say i want to look at if a user is an admin and if he is i want him to go to a special page. i would do something like this in the after insert event

$DB1 = new clsDBYourDBConnection;
$SQL1 = select ACTION from table order by ID desc.
$DB1->query($SQL1);
$RS1 = $DB1->next_record();

global $REDIRECT;

if($DB1->f("ACTION") =="ADMIN")
$REDIRECT = "admin.php";
else
$REDIRECT = index.php";
View profile  Send private message
rado

Posts: 221
Posted: 04/22/2009, 9:13 AM

Thanks for respond aondecker.
My biggest concern is where I can get return code of MySQL itself that tell me is transaction successful or not, so I can insert in my "audit_events" table.

Rado
View profile  Send private message
melvyn


Posts: 333
Posted: 04/22/2009, 1:10 PM

Short answer (you must test the code and try everything).

When you execute the query it always return a true/false value.

  
$db = new clsDB<DBConnection>;  
$SQL = "YOUR QUERY";  
$result = $db->query($SQL);  

At this point result will be true or false, depending of query result. If it got executed you'll have true. If not, you'll have false.

  
if($result){  
  // place your code when query executed ok.  
}else{  
  // query didn't executed.  
}  

The above only test if the query executed or not. It don't test if it returned a set of results. If you want to know.

The following code can help a bit in that way:

  
$result = $db->next_record();  
  
if($result){  
  // the (select) query returned one or more records  
}else{  
  // the (select) query returned zero records.  
}  


All the code, in the block:

  
$db = new clsDB<DBConnection>;  
$SQL = "YOUR QUERY";  
$result = $db->query($SQL);  
  
if($result){  
  // place your code when query executed ok.  
}else{  
  // query didn't executed.  
}  
  
$result = $db->next_record();  
  
if($result){  
  // the (select) query returned one or more records  
}else{  
  // the (select) query returned zero records.  
}  

_________________
Melvyn Perez
Puro Codigo
http://purocodigo.com
View profile  Send private message
rado

Posts: 221
Posted: 04/22/2009, 1:30 PM

You are the MAAAN. Thank you so much Melvyn.
Is there something to verify execution of PHP functions?

I would like to use CCS to handle that. Something like.... "After execution" check return code and update "audit_events" table.

Rado
View profile  Send private message
melvyn


Posts: 333
Posted: 04/22/2009, 1:49 PM

For functions?

Well, I've checked and I can see that lot of CCS functions returns true/false. Also noticed some of them doesn't but I think functions without boolean returns aren't focussed to custom usage. They're called by another codecharge functions.

If you're talking about your own custom functions then it's very single:
  
function doSomething($value){  
  // actions  
  if( $everything_got_ok){  
    return true;  
  }else{  
    return false  
  }  
}  

Think about it: a function with 300 lines can have several exit points, in each one you can exit with false or true. A final return true will be executed if everything got ok (asuming that if something failed you exit with return false).

As told: with functions you can use the same behavior. When you need return values as string or numbers or something so, you can also check with another methods, like theese:
  
$integer_value = calculateSomething($value1,$value2);  
if($integer_value > 0){  
  // executed!  
}else{  
  // not executed  
}  
  
$string_value = getCustomerName($customer_id);  
if(strlen($string_value) > 0){  
  // executed!  
}else{  
  // not executed  
}  

___________
Update:
The function calculateSomething() receives 2 arguments and return an integer.
The function getCustomerName() receives 1 argument and return a string.
_________________
Melvyn Perez
Puro Codigo
http://purocodigo.com
View profile  Send private message
rado

Posts: 221
Posted: 04/25/2009, 9:39 AM

Thanks Melvyn one more time for your help. With my (low) level knowledge of CCS I will be able to make logging database transactions, however going trough every single function of codecharge and do what you suggested is (honestly) to much for me in this stage. I have to leave this for later time.
But generally talking, how you people keep track of all funcions that executed in CCS. So far I recognized 3 areas where the control of application could happened:
1. Database transaction,
2. PHP
3. Browser (Apache)
4. May be Javascript

My biggest concern is how I can debug application in case of the problem. As far as I know php doesn't log any debug log files which you can use for troubleshooting. Does CCS has any mechanisam that I can use for logging (at least from the page perspective - not going trough every single function).

Thanks again for time that you spend to help me.

Rado
View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

PHP Reports

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.