PHP ODBC Query only return 4 rows - php

I try to execute a store procedure in a hana database using php, using this code
$sql="call sp_stockdisponible";
$cursor+=$limite;
$query=$this->conexion($sql);
while($dataProducto=odbc_fetch_array($query))
{
$sabanaProductosStock[]=$dataProducto;
}
But, only returns 4 records, when should return more than 8.000.
¿What's wrong?
Thanks in advance.
What have I tried
Modify php.ini to work with ODBC
Put the SQL code in a PHP script and inside HANA DB
using LIMIT and OFFSET
What am I expect to happen? I need to return the 8.000 records.
Actually, just return 4.

Related

PHP Atlas.ORM returns always the same result

I want to load data from a SQLite database in PHP using Atlas.Orm.
When I run the following snippet, I get a set of 1773 results, but each result is the same!
$atlas = Atlas::new('sqlite:[Path To Database]');
$result = $atlas->select(Stop::class)->fetchRecords();
Can anyone tell me whats wrong here?
After several hours of desperation, I found the issue by myself. The ORM needs the PRIMARY_KEY constant in the corresponding *Table class to be set, otherwise fetching records will fail like this.

PHP Laravel / Oracle compare timestamp . how?

I am trying to extract from my php laravel some data like this:
$x = Carbon::now()->timestamp;
$data=Notifications->where('happened_at','>',$x)
->where('id_user',Auth::user()->getAuthIdentifier());
If I enter this sql statement in my oracle database directly it works perfectly:
select * from notifications where happened_at > '10-06-2017 00:11:12,000000000';
^ this returns correct, however in my php laravel it doesn't return the good rows(returns all the rows from the database)
Later Edit: The where is the problem, I just want to compare the timestamp location in my DB('happened_at') with the current time...I don't know how though
Let's break down your model call code.
// first, you retrieve all notifications and assign them to $data
$data = Notifications::all()
// then, you try to start a new query
->where('happened_at','>',$x)
// then, you continue the new query
->where('id_user',Auth::user()->getAuthIdentifier())
// and finally, you finish the call
;
So basically, you already get all rows at the beginning, and then you try to start building a query that you never execute. (But you can't, since all() returns a collection.)
Remove the all() and finish up with ->get() at the end, and it should work. (Although I don't know anything about Oracle timestamps.)

how to call sybase view using odbc in PHP

I am trying to fetch the records from the sybase view ODBC in PHP but it does not return data.
I am getting records from table but not able to get data from view.
Query -- select * from odb.VP_myview;
odb = odbc DSN
VP_myview = view
Above query does not show any error but same time it does not return any records.
Below is PHP code
<?php
$con = #odbc_connect('DSN','USERNAME','PASSWORD',SQL_CUR_USE_ODBC) or die("<B>Error!</B> Couldn't Connect To Database. Error Code: ".odbc_error());
$query = 'select * from odb.VP_myview';
$result = odbc_exec($con,$query);
$totrec = odbc_num_rows($result);
var_dump($totrec);// it return negative integer number
exit;
?>
It would be really great help. I am trying since last 3-4 days but no success.
From the manual:
Using odbc_num_rows() to determine the number of rows available after
a SELECT will return -1 with many drivers.
That's especially true for Sybase. C.f. this question

sql query not working for stored procedure in PHP

I have a stored procedure in sql server.When I try to use the php function to get the results,its not working.
echo mssql_query(exec MOB_uspcommunication_details $userID,'send');
This gives result as 1 instead of resourceID.When I run the query in sql server its giving me the result.
When I change the second parameter to some other value like this,its working from PHP side.
echo mssql_query(exec MOB_uspcommunication_details $userID,'inbox');
This gives me resourceid#10 and I am getting the results.
For the first query,I am not able to understand why this happens.Please help me
From the PHP documentation:
Return Values
Returns a MS SQL result resource on success, TRUE if no rows were returned, or FALSE on error.
So that means that the first function call returns 1 to indicate there were no rows (1 == true in PHP). The second function call actually retrieves the rows from your table.

Microsoft´s sqlsrv driver for PHP not returning any result when querying "SELECT SCOPE_IDENTITY() AS id"

this query works fine using the php_mssql driver:
INSERT INTO Table(columnName) VALUES ('text');
SELECT SCOPE_IDENTITY() AS id;
Table does have an id column, which is an identity.
I would execute that query, and get the last id in the table.
The same code doesn´t work if the query is executed using Microsoft´s php_sqlsrv driver.
I don´t get any error when executing the query (sqlsrv_query function) , but i get the following error when calling sqlsrv_fetch_array:
"The active result for the query contains no fields"
I´ve googled a lot, and didn´t find no answer, it was a big surprise for me that no one faced this problem before, it seems like nobody is using this driver, even though is the "official" one since PHP 5.3 release...
Thanks.
In the initial CTP the field indices started at 1. Later they were changed to start at 0.
Try something like this:
// connection to the dbserver
$result = sqlsrv_query("INSERT INTO Table(columnName) VALUES ('text'); SELECT SCOPE_IDENTITY() AS ID");
echo "The last insert_id is".lastId($result);
function lastId($queryID) {
sqlsrv_next_result($queryID);
sqlsrv_fetch($queryID);
return sqlsrv_get_field($queryID, 0);
}

Categories