Solved

Transitioning to PDO/MySQL.  Need help  with SELECT statement, Do I have to bind value?

Posted on 2014-12-20
6
89 Views
Last Modified: 2014-12-20
On a select statement without a WHERE clause, do I have to bind anything using PDO?

I am getting the following error:
Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 32 bytes)
on "$query2->execute();" line.


$query2 = $conn->prepare('SELECT * FROM `download');
// Do I bind a value here?
$query2->execute();

while ($row2 = $query2->fetch(PDO::FETCH_ASSOC))
{
    
 echo $row2['image']."<BR>";

}

Open in new window

0
Comment
Question by:lawrence_dev
  • 3
  • 3
6 Comments
 
LVL 58

Accepted Solution

by:
Gary earned 500 total points
ID: 40511308
No you can just do

$query2 = $conn->query('SELECT * FROM `download');

while ($row2 = $query2->fetch(PDO::FETCH_ASSOC))
{
...

Open in new window


But that error means you are running out of memory
Are there a lot of rows being returned?

Search the php.ini file for
memory_limit =

...and increase the limit.
0
 

Author Comment

by:lawrence_dev
ID: 40511320
Thanks Gary!
I have 17040 rows,  None being returned.  If I place php.ini in the same folder, PDO stops working for some reason...  

Still working on it...
0
 
LVL 58

Expert Comment

by:Gary
ID: 40511324
Add this to the top of the php page to get any errors reported

    error_reporting(E_ALL);

32 MB is rather small for a site, 64 or 128 would be better.
But you are returning a lot of rows - is there a reason?

If you are using a custom php.ini file you should place it in the site root.
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 58

Expert Comment

by:Gary
ID: 40511325
I've just noticed a syntax error in your code

Should be (no need for the backticks and you were missing the closing one)

$query2 = $conn->query('SELECT * FROM download');

Open in new window

0
 

Author Comment

by:lawrence_dev
ID: 40511331
Thanks Gary for all of your help!!  Memory Limit issue with IonCube required for PDO.  Fixed it and it is good!
0
 

Author Closing Comment

by:lawrence_dev
ID: 40511333
Thanks again!
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question