I have a stored procedure that client has made.
Now I have to access it and process data in my laravel app.
I have no problems with connecting to SQL but the problems starts when passing in parameters.
Here is my code:
$connections = DB::connection('sqlsrv')
->select(EXEC [stored].[procedure].[here] $param1, $param2);
The error I got back is:
The active result for the query contains no fields
I have searched for many hours in forums and here is what I have found:
$connections = DB::connection('sqlsrv')
->select(DB::raw('EXEC [stored].[procedure].[here] $param1, $param2'));
Error I got back is:
The active result for the query contains no fields.
I have installed SQL driver and OBDC driver.
Any help would be much appreciated
Don't know if this will help but this answer suggests you put your DB::raw around just the params instead of the EXEC stored.proc.name.
So instead of
$connections = DB::connection('sqlsrv')->select(DB::raw('EXEC [stored].[procedure].[here] $param1, $param2'));
Try
$connections = DB::connection('sqlsrv')->select('EXEC stored.proc.name' . DB::raw($param1, $param2));
OK. So I found out the issue.
It turns out the client sent me over a variable with xml.
As far as I figured out from Microsoft docs then you cant pass xml as a varable because if you call the SP from an application it is gonna pass it as an array and application cant parse xml into array directly. You have to do it on your own.
What can be done instead is to pass xml as a value of an array and then take it from there.
Related
I am working with Laravel and I am using a database in Sql Server. I need to execute a function that was do in Sql Server but I do not how to execute it.
The function in Sql Server is something that it:
Select dbo.functionName (848,95,37)
I try to execute it with this:
DB::connection('database')->select('Select dbo.functionName ?,?,?',array(848,95,37))
but Laravel return it: Cannot access empty property
I hope you can help me.
I had this problem too, i solved that like this:
DB::connection('database')->select('Select dbo.functionName (?,?,?) as result',array(848,95,37))
May be this will work (Added parenthesis)
DB::connection('database')->select('Select dbo.functionName (?,?,?)',array(848,95,37))
I'm new to SAP - PHP programming and I use SAPRFC for calling my SAP FM.
I use saprfc_import - saprfc_table_init - saprfc_table_read function before, but because my work, I need to pass a lot of import parameter value and because if I use this, I need to open - close SAP connection and my webpage become so slow.
Recently I read about SAPRFC class and it have callFunction function that use array as import parameter and I think it can help me, but when I debug my SAPRFC class, my import parameter always empty or it will be error like this:
Import-Parameter : 'parameter-name' could not be set. (Does it exist?)
I use this way to call my function
$arrayParam = array_push(["param_name"=>"param_value"]);
$result = $sap->callFunction("FM_NAME",
array(
array("IMPORT","param_name",$arrayParam),
array("EXPORT","output_column",array())
)
);
Is my way to call it right or not?
after searching via google for a while,
i've found way to solve my problem here
saprfc class on that github is more perfect than on saprfc official because it already modified and now i can pass an 2 dimension array as table for my parameter
I'm having several problems with an implementation in php for working with mongoDB
My case is that I made a function which recover an mongoDB database in $_SESSION['mongoDb'] variable, selects a collection and then use the function find($where, $fields).
My error is
Fatal error: Call to a member function find() on a non-object in...
I've tried checking mongodb php driver and others but the problem still existing...
EDIT: More info about.
Thanks for the post Eternal1, it's a bit confusing because same code is working in a production server but not my localhost XAMPP server.
For the one who ask me for the code, here you are:
public function generic_select_mongo ($collection, $fields, $where, $order, $limit)
{
$mongoBd = $_SESSION['mongoBd'];
$col = $mongoBd->$collection;
$res = $col->find($where, $fields);
$res->sort($order);
$result = array();
while ($docs = $res->getNext())
{
$result[] = $docs;
}
return $result;
}
I'm gonna investigate about Session in php. Sorry for the answer with additional info.
MongoDB connection, as other DB connections, is of resource type, which can't be serialized and therefore properly stored into session. PHP session manual states:
Some types of data can not be serialized thus stored in sessions. It
includes resource variables or objects with circular references (i.e.
objects which passes a reference to itself to another object)
PHP Sessions
We have an AS400 RPGLE program created within the library LMTLIB, which is called ARTEST.
It has a single numeric inout parameter, which just returns 2
$myVar = "1";
$db = Zend_Registry::get('config')->resources->multidb->as400;
$abstractAdapter = new Zend_Db_Adapter_Db2($db);
//Gives the message "Invalid bind-variable position 'myVar'"
$sql = 'CALL QSYS.QCMDEXC(\'CALL LMTLIB.ARTEST PARM(?)\', 0000000026.00000)';
//Gives the message "Token PARM was not valid. Valid tokens: ( INTO USING. SQLCODE=-104"
$sql = 'CALL LMTLIB.ARTEST PARM(?)';
//Gives the message "ARTEST in LMTLIB type *N not found. SQLCODE=-204"
$sql = 'CALL LMTLIB.ARTEST (?)';
$stmt = new Zend_Db_Statement_Db2($abstractAdapter, $sql);
$stmt->bindParam('myVar', $myVar, 4, 1);
$stmt->execute();
Now, i can kind-of understand why the third SQL statement would fail with the "not found" message... because it is not a table / file, but rather an RPGLE program.
The thing thats irritating, is that if i remove the (?), and simply put in (1)... the SQL call appears to be successful, and the RPGLE program shows it had been called. However, I'm then not able to see what the response from the program was.
Thanks in advance for any help!
Generally, the database manager uses the CALL statement to invoke a stored procedure. When it does that, it looks for a stored proc whose parameter signature matches the signature of the CALL.
If there's no stored proc with that name and signature, the database manager tries to call a program. Again, there's a parameter matching process that happens.
http://publib.boulder.ibm.com/infocenter/iseries/v5r4/topic/db2/rbafzmstcallsta.htm
I suggest creating a stored procedure so you can get the parameters matched properly.
IBM RPGLE can interface with the Zend framework through webservice calls.
Scott Klement goes over some of the basics of this here.
Depending on your application, this may be the best way to interface with RPG code. Webservices can be made to call many RPG programs and iSeries tables, and return a catered result set. Zend would see this the same as any other RESTful call, which could be handled by your models.
It took me a while to get soap configured in php. Now I'm just trying to learn about it. I'm using the web service here to learn:
http://www.webservicex.net/WCF/ServiceDetails.aspx?SID=19
It says the WSDL is here:
http://www.webservicex.net/stockquote.asmx?wsdl
and this is my code:
$client = new SoapClient('http://www.webservicex.net/stockquote.asmx?wsdl');
$result = $client->getQuote("AAPL");
echo $result;
I'm getting an error saying "Object of class stdClass could not be converted to string". Now I realize that $result is an object, and I'm wondering how do I access data that the server populated? I tried to understand the WSDL but I'm getting nowhere. Is it supposed to be something like:
$result->price
? (That doesn't work by the way...)
Ideas?
When curious about datatypes from the soapserver, use the SoapClient->__getTypes() & SoapClient->__getFunctions() methods
If you return is still not clear, var_dump() your return and examine it.