This topic is locked
[SOLVED]

 Two Databases with same table and fields

4/3/2015 5:02:51 PM
PHPRunner General questions
J
jmartin17 author

I have a project with connection to two Databases with same table and fields I need to create a way to read from one by key and update the other.

Tried using DAL by adding a Update Selected button on List Page. It created a Update Select with three events. Client Before, Server and Client After.
Client Before has:
function OnClient Before(params,ctrl)

{

// Put your code here.

params["txt"] = "Select Record";

ctrl.setMessage("Selecting Record on server...");
// Uncomment the following line to prevent execution of "Server" and "Client After" events.

// return false;

} // function OnClient Before
Server has:
function OnServer($params, $result)

{

//** Save new data in another table ****

// Insert record using Data Access Layer (DAL).

// Another table needs to be part of the project.

global $dal;
$tblEvents = $dal->Table( "PHPAOVIEW1","", "ODBC:PCCRemote");

$tblEvents-Value["CLIENTID"]=$values["CLIENTID"];

$tblEvents-Value["PHPOVRID"]=$values["PHPOVRID"];

$tblEvents-Value["PHPOVTBID"]=$values["PHPOVTBID"];

$tblEvents-Value["PHPOVLK"]=$values["PPHPOVLK"];

$tblEvents-Value["PHPOVURL"]=$values["PHPOVURL"];

$tblEvents-Value["PHPOVIMGPATH"]=$values["PHPOVIMGPATH"];

$tblEvents-Value["PHPOVNOTES"]=$values["PHPOVNOTES"];

$tblEvents-Add();
}

$result["txt"] = $params["txt"]."Records were updated!";

} // function OnServer
Client After has:
function OnClient After(result,ctrl)

{

// Put your code here.

var message = result["txt"];

ctrl.setMessage(message);

} // function OnClient After
The table PHPAOVIEW is on my Windows 7 Pro system connected as odbc:i270 and there is a table PHPAOVIEW on a remove system connected as

odbc:PCCRemote.
I can't find any information about the parameters: params,ctrl for event Before Client but it does put out the message.

the parameters: $params, $result for the Server I can't fine if when clicking the button it passes the current record?
The Server and Client After events I don't think work? It just displays the message, Selecting Record on server..., and never completes.

In the notes it says:
PHP code executed on the server side.
Parameters

$params - array of parameters sent from the client

$result - array of values to return from the server
Notes

getCurrentRecord() - returns an associative array with field values (field name => value)

Example:
$data = $button->getCurrentRecord();

$result['record'] = $data;

$result['email'] = $data["email"];

getNextSelectedRecord() - consequently returns arrays with values from records checked off on the List page.
Can any one point me to a example? or tell me what is wrong?
I appreciate it.
James

jmartin@jmartinassociates.net

C
cgphp 4/18/2015

You can find useful informations here: custom button

J
jmartin17 author 4/18/2015



You can find useful informations here: custom button


Cristian Gilè:
I had tried that but it took a while to finally figure it out and find that I was not able to get it to write to the second connection and

write the record? There was no example in manual, that I could find. Alexey Kornilov with support@xlinesoft.com replyed to a e-mail telling

me DAL deals with the database tables, not the PHPRunner custom views, so your $tblEvents=... line is wrong and advised me to use: $tblEvents = $dal-Table( "PHPAOVIEW","", "ODBC:PCCRemote"); I still could not get it to work. I thought I found the problem in the Manual. It looked like DAL only works with the Primary connection and not the secondary one which is where my other two tables were at:
I decided because the tables were same name and field were the

same, even though PHPRunner add a 1 to the end of the remote table name that maybe I needed to change the table names and field name to get it to work and it did:
The Project maintains 4 files, two files PHPAOVIEW and TABAOVNAC on my system and two file PHPAOVIEW1 and TABAOVNAC1, are the ones that PHPRunner added the 1 to each table, and are on a remote system. They all have an ODBC connection. The problem was when I update PHPAOVIEW on my system I want it to also save the same record to the PHPAOVIEW1 on the host system and selected it from the list program that had the DAL events it gave no errors and would not write to the remote system
I was trying to use this method because it was all I found when looking for a PHPRunner solution to

enter a key value and retrieve all records and write them to another table or update to another table.

What I understood DAL would do was save record or insert records in another table based on the event of

add or update record in primary table or selected with events to retrieve and insert with PHPRunner connected to multiple databases.
What I did was create two new tables with different name and fields with different name a go to the List page of the file in the Maintenance Program and add a send Button to each row and create a event for Send Record leaving the Client Before empty and adding to the server



function OnServer($params, $result)

{

// Put your code here.

$record = $button->getCurrentRecord();

$result["CLIENTID"]=$record["CLIENTID"];

$result["PHPOVRID"]=$record["PHPOVRID"];

$result["PHPOVTBID"]=$record["PHPOVTBID"];

$result["PHPOVLK"]=$record["PHPOVLK"];

$result["PHPOVURL"]=$record["PHPOVURL"];

$result["PHPOVIMGPATH"]=$record["PHPOVIMGPATH"];

$result["PHPOVNOTES"]=$record["PHPOVNOTES"];

global $dal;
while ( $data = $button->getNextSelectedRecord() ) {

$tblEvents = $dal->Table( "PHPWKVIEW");

$tblEvents->Value["WKCLIENTID"]=$result["CLIENTID"];

$tblEvents->Value["WKOVRID"]=$result["PHPOVRID"];

$tblEvents->Value["WKOVTBID"]=$result["PHPOVTBID"];

$tblEvents->Value["WKOVLK"]=$result["PHPOVLK"];

$tblEvents->Value["WKOVURL"]=$result["PHPOVURL"];

$tblEvents->Value["WKOVIMGPATH"]=$result["PHPOVIMGPATH"];

$tblEvents->Value["WKOVNOTES"]=$result["PHPOVNOTES"];

$tblEvents->Add();

}

$result["txt"] = "Records were updated.";
;


and the event Client After:



function OnClient After(result,ctrl)

{

var message = result["PHPOVRID"] + '<BR>' + result["PHPOVLK"];

ctrl.setMessage(message);


and it wrote to the different table on the host system. I still have to ftp the different table(file) to the remote and

insert or update the records on the remote system. I was hoping to be able to write directly from host system to remote

system updateing the same table with same fields cutting out all the steps of maintaining different table, ftp table and create

insert or update on remote system.
Even thought there are some good examples and the forum is available its too simple and support provides good support but if

more complex you have to pay for added support or figure it out for your self which takes time.
I have used WebSmart PHP from BCD Software for several years but it cost a lot more for all the same features as PHPRunner Enterprise

has so that is why I am making the change.
When I decided to change from WebSmart PHP to PHPRunner, I knew if I ever worked close with someone on

a project there would be more to consider with PHPRunner than with WebSmart PHP.
WebSmart PHP has templates and creates a program with certain functions. Example

page at a time program that will let you add, display, change or delete records.
If I work on a project I would work on one program while someone else might

work on another one. Therefore no problem consolidating all the source etc together

but with PHPRunner it works on the whole project
making it harder to work together since you cannot separate just one program from

another one and combine them easily.
In Websmart PHP it ftp's from the output directory the one program

to the server without any other necessary supporting program, scripts or directories.

but in PHPRunner that is not the case. So one programmer working on part of the same

project would make it difficult to update the server without changing what anyone

else has uploaded.
So when I was searching for an answer to my DAL problem I was trying to solve, the xlinesoft

blog had this information about Best practices: multiple developers working on the same project

and it look like a possible solution. It also pointed out how much more complex PHPRunner

is than WebSmart PHP and to me it meant a lot more capability and that they recognize the

need to support more than on developer working on same project.
[url]http://xlinesoft.com/blog/2011/06/08/best-practices-multiple-developers-working-on-the-same-project/[/url]

Best practices: multiple developers working on the same project
I have got great support for xlinesoft but I need to find some associates that want to work with me.
Have a great day.
James