CodeCharge Studio
search Register Login  

Visual Web Reporting

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

YesSoftware Forums -> CodeCharge Studio -> PHP

 MySQL functions available on Insert?

Print topic Send  topic

Author Message
Jer

Posts: 25
Posted: 10/29/2008, 9:08 PM

I'm trying to use some built-in functions in MySQL during an INSERT.

I'm now wondering if it's possible to do so with CodeCharge.

$this->InsertFields["first_name"] = array("Name" => "first_name", "Value" => "AES_ENCRYPT(first_name, 'rpassword')", "DataType" => ccsText);

I looked at the password function but that doesn't appear to be suitable. It used a str_replace to replace {password}

with the md5 code.

I've checked the docs and see nothing about this.

Am I trying to do something that is simply not possible here?

Thanks,

Jer
View profile  Send private message
melvyn


Posts: 333
Posted: 10/30/2008, 9:38 AM

Create a BeforeInsert event and use this:
  
$Component->my_form->my_password->SetValue( md5( $Component->my_form->my_password->GetValue() ) );  

It gets the current value for "my_password" convert to md5 and then replace in the current form before inserting.

The AES_ENCRYPT version:
  
global $DBConnection;  
$password = $Component->my_form->my_password->GetValue();  
$sql = "INSERT INTO users_table (password) VALUES(AES_ENCRYPT(".$password."));  
$DBConnection->sql($sql);  
  
if($DBConnection->NextRecord){  
//your query has been run  
}else{  
//there's an error  
}  

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

Posts: 25
Posted: 10/30/2008, 10:27 AM

Hi Melvyn,

Thanks for the help.

It's not just the password field we need to encrypt, decrypt. There are hundreds of fields in multiple tables.

I have a feeling that for thos project I should have stuck with CodeCharge 1. That would have been a lot easier for the amount of custom code.

Jer
View profile  Send private message
melvyn


Posts: 333
Posted: 10/30/2008, 12:08 PM

I understand.

Create a function, in external file, include it and call the function for each field. OR create a custom insert. If your database supports engine InnoDB you can create an stored procedure.

Also, you can do it after insert and after update, how?

Insert everything normally. Next in the after insert event:
1) Get last inserted row and set it to $last_id
2) "UPDATE my_table SET my_field1 = AES_ENCRYPT(my_field1), my_field2 = AES_ENCRYPT(my_field3), my_field3 = AES_ENCRYPT(my_field3) WHERE id = " . $last_id



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

Posts: 25
Posted: 10/30/2008, 1:10 PM

Hi Melvin,

Thanks for the suggestion to encrypt after insertion. That appears to be the method that's quickest.

Jer
View profile  Send private message
mamboBROWN


Posts: 1713
Posted: 10/31/2008, 5:36 AM

Jer
If your issue has been resolved could you please put [RESOLVED] or [SOLVED] in the header of this thread. Thanks.
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.