cancel
Showing results for 
Search instead for 
Did you mean: 

Business One PHP access

pm_witmond
Participant
0 Kudos

Hi,

I'm trying to access SBO with PHP

Connecting to the company object is working fine

But the next step (getbusinessobject) is not working

Does anybody have tips ?

This is the current code :

<?php

echo "SBO PHP TEST<br>";

$vCmp=new COM("SAPbobsCOM.company") or die ("No connection");

$vCmp->server = "(local)";

$vCmp->CompanyDB = "sbodemo_dutch";

$vCmp->username = "manager";

$vCmp->password = "manager";

//$vCmp->language = "ln_English";

//$vCmp->UseTrusted = True;

$lRetCode = $vCmp->Connect;

echo $vCmp->CompanyName;

echo '<br>';

$vItem = $vCmp->GetBusinessObject(oItems);

$RetVal = $vItem->GetByKey("A1010");

echo '$vItem->Itemname';

echo '<br><br>Ready';

?>

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

<?php

echo "SBO PHP TEST<br>";

$vCmp=new COM("PERPETUA.company") or die ("No connection");

$vCmp->server = "(localhost)";

$vCmp->CompanyDB = "SYSTEM";

$vCmp->LicenseServer = "localhost:30000";

$vCmp->username = "manager";

$vCmp->password = "manager";

$vCmp->DbServerType(PERPETUA.BoDataServerTypes.dst_MSSQL2008);

$lRetCode = $vCmp->Connect;

echo $vCmp->CompanyName;

echo '<br>';

$vItem = $vCmp->GetBusinessObject(oItems);

$RetVal = $vItem->GetByKey("A1010");

echo '$vItem->Itemname';

echo '<br><br>Ready';

?>

didnot work?

1.How to connect the Sap b1 database.

2. How to entries are pushed into PHP to SAP b1 database?

Any idea.?

Former Member
0 Kudos

Please try this-->

<?php

$vCmp=new COM("SAPbobsCOM.company") or die ("No connection");

$vCmp->DbServerType=6;

$vCmp->Server = "SQL_SERVER_NAME"; \\Server

$vCmp->CompanyDB = "SQL_DB_NAME"; \\SBODemoIN

$vCmp->LicenseServer = "LICENSE_SERVER_WITH_PORT"; \\ Server:30000

$vCmp->UserName = "(B1_company_ussername"; \\ manager

$vCmp->Password = "B1_company_password"; \\ 1234

$vCmp->DbUserName = "sa";

$vCmp->DbPassword = "sql_server_password"; \\ 1234

$lRetCode = $vCmp->Connect;

echo $vCmp->CompanyName;

?>

--Note-- Don't forget to replace credentials with your actual one.

Regards,

ARYA

schadrackrurangwa
Discoverer
0 Kudos

Hi Gaurav,

Did you ever try to connect SAP with PHP?

I tried to do that but I'm getting result as -8037 those are the connection codes I used

<?php

$mycomp = new COM("SAPbobsCOM.Company") or die("Cannot start SBO");

$mycomp->DBServerType =6;

$mycomp->Server="192.168.0.103";

$mycomp->LicenseServer = "192.168.0.103:30000";

$mycomp->DbUserName = "sa";

$mycomp->DbPassword = "****";

$mycomp->UserName = "manager";

$mycomp->Password = "****";

$mycomp->CompanyDB = "SBODEMOUS";

echo $mycomp->Connect();

?>

I'm using SQL server 2008 and Xampp for PHP file,

If it's possible please help me to check in above codes.

christophe_averous
Active Participant
0 Kudos

Hi,

Thanks a lot for this post.

For me the following is running

$oItem=$vCmp->GetBusinessObject(4);

$RetBool=$oItem->GetByKey("A1010");

echo "<br>". $RetBoll;

echo "<br>". $oItem->ItemName;

This return:

1

Nom de l'article

For recordset

$oRS=$vCmp->GetBusinessObject(300);

$oRS->DoQuery("Select Top 10 itemcode,itemName from oitm")

$oRS->MoveFirst

while ($oRS->EOF!=1){

echo "<BR>".$oRS->Fields->Item(0)->value." ".$oRS->Fields->Item(1)->value;

$oRS->MoveNext;

}

To add an order

$oOrder=$vCmp->GetBusinessObject(17);

$oOrder->CardCode="C01";

$oOrder->DocDueDate="06/04/2009";

$oOrder->Lines->Itemcode="A1010";

$oOrder->Quantity=100;

$RetCode=$oOrder->Add;

$Nk="";

if ($RetCode==0) {

$vCmp->GetNewObjectCode($Nk);

echo "<BR>" ."Doc Entry ".$vCmp->GetNewObjectCode($Nk);

}

Christophe

rasmuswulff_jensen
Active Contributor
0 Kudos

Hmm.. ok

Try instead of this line: $vItem = $vCmp->GetBusinessObject(oItems);

This:

$vItem = $vCmp->GetBusinessObject("oItems");

or this:

$vItem = $vCmp->GetBusinessObject(4);

or this:

$vItem = $vCmp->GetBusinessObject("4");

Don't really know how PHP respond to the DI-API.. Never seen anyone do DI-work using PHP before..

pm_witmond
Participant
0 Kudos

Already tried this but it's always the same - nothing happens

All code before the getbusinessobject is working fine but after this the script stops running

rasmuswulff_jensen
Active Contributor
0 Kudos

Hmm... Perhaps something internal in the SDK don't work with PHP, or there's some conversion problems with objects comming back from getbusinessobject.

Sorry.. don't think I can help anymore.

pm_witmond
Participant
0 Kudos

Thanks for your help

Regards,

Paul

pm_witmond
Participant
0 Kudos

Working PHP script :

<?php

$vCmp=new COM("SAPbobsCOM.company") or die ("No connection");

$vCmp->server = "(local)";

$vCmp->CompanyDB = "sbodemo_dutch";

$vCmp->username = "manager";

$vCmp->password = "manager";

$lRetCode = $vCmp->Connect;

$vItem = $vCmp->GetBusinessObject(305);

$rs = $vItem->getitemprice("sw2","a1000",70,"17-07-2006");

echo $rs[0]->value;

echo $rs[1]->value;

?>

305 = BoBridge

SW2 = cardcode

A1000 = itemcode

70 = amount

rasmuswulff_jensen
Active Contributor
0 Kudos

Hmm. Thats one of the NonBusiness objects of the SDK... Try the recordset ... If that work and still not the business objects there might be some strange kind of limit to non business objects.

rasmuswulff_jensen
Active Contributor
0 Kudos

Are you sure you have a valid connection ($IRetCode == 0)..

Possible problem if you dont have a connection

- Seems you are missing $vCmp->LicenseServer = "servername:30000";

- Are you sure you PHP-user have Usetrusted (Win Auth) access? use properties dbUsername and dbPassword instead

The DI Server should be a much better approach when working with PHP (Actually I didn't even know that PHP could work with COM objects)... The DI Server uses a web-service architecture...

pm_witmond
Participant
0 Kudos

Thanks for the answer

The connection is valid (retcode==0)

Adding the dbusername/license server did not solve the problem.