Questions tagged [fetchall]
165 questions
3
votes
1 answer
Python SQL cursor/fetch: When does the database query complete running?
I had a question regarding the python IBM_DB package (but I think it could be applied to any of the packages that employ the connection/cursor logic i.e. pyodbc).
When the cursor.execute() method is called, it executes an sql query on the database.…

Frank_Sma
- 47
- 4
3
votes
1 answer
My PHP PDO fetchAll() code returns one row instead of all results on MySql column table
I'm trying to populate all results from one column of MySql table through PHP and PDO FetchAll() with Prepared Statements but my code just return one row instead of all results. I saw this question here (PHP PDO returning single row) that is similar…

Michel Xavier
- 133
- 3
- 14
3
votes
0 answers
Different results from printing cursor.fetchall()
I have a cursor on database db like :
db = MySQLdb.connect("localhost", "user", "pass")
cursor = db.cursor()
cursor.execute(sql)
print(cursor.fetchall())
rows = cursor.fetchall()
print(rows)
Why first output is an empty tuple () while the second…

alizeyn
- 2,300
- 1
- 20
- 30
3
votes
2 answers
How do I make a list out of rows from a database using cursor.fetchall with pyodbc?
I have a script that works fine on a simple list. It removes some unwanted characters from a list of words, make them match with each other and returns several lists of similar words (with a 0.6 ratio).
But now I need it to work on an Access…

Alice Phoenix
- 55
- 1
- 7
3
votes
1 answer
What's the difference between using "c.fetchall()" vs. just assigning "c.execute(SELECT...." to a variable?
I'm pretty certain that for the most they are functionally the same but I'm wondering if there's some cases where they are not and what's going on under the hood that makes it so?
Example:
c.execute("""SELECT * FROM players WHERE team = ?;"""),…

shbooms
- 83
- 1
- 10
3
votes
1 answer
PHP PDO fetchAll() vs direct foreach loop
Is there any difference between these two:
$stmt = $db->prepare('SELECT * FROM ARTICLES');
$stmt->execute();
foreach ($stmt as $article) {
echo $article['title'];
}
and
$stmt = $db->prepare('SELECT * FROM…

petek
- 953
- 4
- 14
- 24
3
votes
4 answers
How to i split String by new line and by ";" and then fetchall as row
I have txt file which looks like
Stefan;Mihajlovic;2;3, 2, 3, 2, 3, 2;100
Milutin;Milankovic;1;2, 3, 4, 5, 6, 89;1000
I managed to split it by new line using code below
$array = file('test.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
…

Stefan Michelangelo Mihajlovic
- 164
- 1
- 11
3
votes
1 answer
Can I do a treatement of returning values directly in SQL query
I was wondering if it was possible for a SQL query to return datas using some entries in the SQL. I'm sorry if it's not explicite (not english here, i guess you figured it out), so let's see an example :
$req = $bdd->prepare('SELECT u.u_id,…

Vae
- 636
- 1
- 8
- 16
3
votes
0 answers
With bookshelf.js, how do you loop through all models in batches?
With bookshelf.js it is easy enough to fetch all records for a given model using Model.fetchAll and then loop through them, like so:
SomeModel.fetchAll().then(function(results) {
results.models.forEach(function(model) {
...
…

Ben Lee
- 52,489
- 13
- 125
- 145
3
votes
1 answer
php PDO fetchAll(), simple result
So many questions about PDO::fetchAll() but still I can't find my answer. I need to fetch my results as it is returned by the MySQL. for example if I have columns id, name, age to be returned like this:
array(
"id"=array(1,2,3),
…

Mohammad
- 90
- 7
3
votes
1 answer
Variable is undefined inside a function, cannot reach MySQL $connection inside a function
I have a code that works when I use it on a page but Im trying to make this a function. I cant get it to work, it seems like the variables $customer and $system arent being sent through to the code. Even if I type it in Raw. Any idea whats wrong?…

R2D2
- 131
- 1
- 2
- 10
3
votes
4 answers
pdo fetchAll() returns empty array()
I have been trying for over a day now to get FetchAll() method to help me display array from database. But all my efforts have failed. Instead of the print_r() returning an array, it gives me this array(). Kindly, help me out.
The code in class page…

user2947216
- 39
- 1
- 4
3
votes
2 answers
PDO fetchAll not returning all rows
So I am trying to get multiple things from database. It is not working.
In my functions file I have:
public function getAllMultiple($username, $course) {
foreach ($course as $key) {
$query = $this->database->db->prepare("SELECT…

user1475632
- 196
- 1
- 11
3
votes
2 answers
Symfony Doctrine : get field value in foreach loop on fetchAll()
I'm trying to display some fields of a table 'Post' using a raw query :
$connection = $em->getConnection();
$statement = $connection->prepare("SELECT * FROM Post WHERE category_id = 1");
$statement->execute();
$posts =…
user2094540
3
votes
3 answers
How much data is too much for PDO fetchAll()
I have searched here but can't find anything using the search terms I can come up with. There is probably another post here somewhere that would answer my question but I have failed to find any.
The PHP manual states:
Using this method to fetch…

codeguerrilla
- 452
- 4
- 16