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))
Related
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.
I would like to know if there is an equivalent method to laravel method dd() for Cake PHP.
If you don't know, dd() dump the given variable and end execution of the script.
Thanks you.
Try adding a prd() function into bootstrap.php
function prd($var)
{
pr($var);
die;
}
source: http://debuggable.com/posts/make-your-life-easier-with-these-five-cakephp-quicktips:48170ee5-0cc0-4815-af60-7c264834cda3
You could also add it to cakephp/app/Config/helpers.php
https://github.com/larapack/dd
Very straightforward to install via Composer.
Jus use dump($var);
After that you can stop the execution with exit;
As you know, we can use the method DB::getQueryLog() to print the sql statement in Laravel 4.
But it doesn't work in Laravel 5.
Query log is disabled by default in L5. Call
DB::connection()->enableQueryLog();
$queries = DB::getQueryLog();
before trying to log it. See the docs for more info
.
if you want to see the currently running SQL query you can use this
https://github.com/itsgoingd/clockwork
installation instructions are clearly mentioned in the README file
I'm successfully using ZF2.2
Everything was working fine until a requirement arised to close the sql connection explicitly.
I know PHP closes all extra db connections after some time.
But I wanted to do this explicity something like $adapter->closeConnection();
Please tell me there is something which can help me.
If you have the adapter in $adapter, this should work:
$adapter->getDriver()->getConnection()->disconnect();
You should get the db_adapter and then get the connection (getConnection()) and with this object you will be able to use the disconnect() method.
My project is working fine on my local machine but not on the web server. I think it is the stored procedures, because the error that I am getting is:
Fatal error: Call to a member function fetch_array() on a non-object in ...
The collation of the database is "utf8_general_ci".
Just a simple example:
I have a stored procedure called offices:
CREATE PROCEDURE offices()
BEGIN
SELECT * FROM offices;
END//
And the php code:
<?php
require ("db.php");
$db = dbConnect();
$result = $db->query("CALL offices()");
while(list($id, $city, $address) = $result->fetch_array())
echo "($id) $city: $address ";
?>
What happens on the database server, when you CALL offices() manually? Any errors? If I had to guess, it looks like the offices() function is not defined on the server, or fails when invoked (table offices doesn't exist?).
To me it looks like the $result is not a object or not initialized. Can you show us the code in your db library. Specifically the query function...
Make sure your db user which was used to install the schema has privileges to create stored procedures. If you are unsure if they are on the server, you can do
SELECT * FROM `information_schema`.`ROUTINES`;
..to see which procedures have been succesfully created.
Keep in mind the majority of shared hosting services do not support triggers, procedures etc.
you are probably running a different version of your database at the remote server.
so the query method is failing and is not returning what should return.
Looks like your auth does not have allowed to use DB procedures at the server