PDO expeced array not returning only a boolean of 1 on webpage The Next CEO of Stack OverflowHow to return only the Date from a SQL Server DateTime datatypeAre PDO prepared statements sufficient to prevent SQL injection?Which MySQL data type to use for storing boolean valuesPHP: Delete an element from an arrayUsing boolean values in CHow to declare and use boolean variables in shell script?Check if at least two out of three booleans are trueSerializing / Unserializing a PHP ArraySQL select only rows with max value on a columnPDO::FETCH_CLASSTYPE - unexpected result

Make solar eclipses exceedingly rare, but still have new moons

What connection does MS Office have to Netscape Navigator?

Calculus II Question

Sending manuscript to multiple publishers

What is the result of assigning to std::vector<T>::begin()?

Real integral using residue theorem - why doesn't this work?

Preparing Indesign booklet with .psd graphics for print

Indicator light circuit

How did people program for Consoles with multiple CPUs?

How do I transpose the 1st and -1th levels of an arbitrarily nested array?

How to safely derail a train during transit?

Won the lottery - how do I keep the money?

MessageLevel in QGIS3

Is it ever safe to open a suspicious html file (e.g. email attachment)?

What happened in Rome, when the western empire "fell"?

Interfacing a button to MCU (and PC) with 50m long cable

How do I make a variable always equal to the result of some calculations?

How to avoid supervisors with prejudiced views?

What does "Its cash flow is deeply negative" mean?

Would this house-rule that treats advantage as a +1 to the roll instead (and disadvantage as -1) and allows them to stack be balanced?

How to count occurrences of text in a file?

Is there an analogue of projective spaces for proper schemes?

Why didn't Khan get resurrected in the Genesis Explosion?

Is it my responsibility to learn a new technology in my own time my employer wants to implement?



PDO expeced array not returning only a boolean of 1 on webpage



The Next CEO of Stack OverflowHow to return only the Date from a SQL Server DateTime datatypeAre PDO prepared statements sufficient to prevent SQL injection?Which MySQL data type to use for storing boolean valuesPHP: Delete an element from an arrayUsing boolean values in CHow to declare and use boolean variables in shell script?Check if at least two out of three booleans are trueSerializing / Unserializing a PHP ArraySQL select only rows with max value on a columnPDO::FETCH_CLASSTYPE - unexpected result










1















I am working to create a content class which will pull all content from the database via a PDO, then run the results through a method which will convert the results into objects, and the loop through the objects, and echo the object to a specific module of the webpage.



What is expected



When the class is activated, there will be an instance created via a PDO that will retrieve the needed data from the mysql database. Then this information will echo out and display on the webpage.



What is happening



I end up with no errors and the boolean number "1" where content should be. At first I thought this was an sql error. I get the same result "1" if I use print_r($query_result). See my tests below.



My class code is below



 <?php


class Content

// --- START OF ACTIVE RECORD CODE ---

public $n_id;
public $n_name;
public $n_text;
public $n_photo;

// Instantiating a STATIC Database Connection for the class to use
static protected $dbconnect;

static public function database($dbconnect)
self::$dbconnect = $dbconnect;

// constructing arguments

public function __construct($args=[])

$this->n_id = $args['n_id'] ?? '';
$this->n_name = $args['n_name'] ?? '';
$this->n_text = $args['n_text'] ?? '';
$this->n_photo = $args['n_photo'] ?? '';


// Multi use method to pass in sql that will execute the PDO only two parameters are bound ID and contentText.
static public function find_by_sql($sql)

// -------------BEGIN PDO-----------

// preparing PDO by loading sql, calling db connection, and storing in variable $stmt

$stmt = self::$dbconnect->prepare($sql);
// Binding Parameters for sql
$stmt->bindParam(':nid', $n_id, PDO::PARAM_INT);
$stmt->bindParam(':nall', $n_name, PDO::PARAM_STR);
$stmt->bindParam(':ntext', $n_text, PDO::PARAM_STR);
$stmt->bindParam(':nphoto', $n_photo, PDO::PARAM_INT);
// executing $stmt PDO and storing the result in $stmt
$query_result = $stmt->execute();
return $query_result;
// clearing the PDO after information is stored in $record
$stmt->closeCursor();


// ------------END PDO ----------

// Checking to see if a result exist. If nop result is stored in $stmt, then it will echo "Database query failed."
if(!$query_result)
exit("Query doesn't exist.");

// -------- BEGIN TURNING RESULTS INTO OBJECTS --------
$object_array = [];

// The result $stmt will be stored in the variable $record

while($record = $query_result->fetchAll())

// Taking $record and passing it to the static method instantiate() - see below. This method will return the $object_array.

$object_array[] = self::instantiate($record);



return $object_array;

// ------------ END TURNING RESULTS INTO OBJECTS --------


// method to test passing $sql to method find_all_sql();

static public function find_all()

$sql = "SELECT * FROM nmain WHERE nid = :id AND nall = :nall AND ntext = :ntext AND nphoto = :nphoto";
return self::find_by_sql($sql);



// --- BEGIN INSTANTIATE METHOD TO CREATE OBJECTS ---

static protected function instantiate($record)
$object = new self;
// Auto assign values
foreach($record as $property => $value)
if(property_exists($object, $property))
$object->$property = $value;


return $object;

// ----- END INSTANTIATE OF RECORD TO CREATE OBJECTS ---

// ---END OF ACTIVE RECORD CODE---



?>

**On my html webpage:**

$contents = Content::find_all();
foreach ((array) $contents as $content)
echo $content;



What I have tested



This is the output I get when I run var_dump($stmt);



object(PDOStatement)#3 (1) ["queryString"]=> string(119) "SELECT * FROM ndb WHERE id = :id AND nall = :nall AND ntext = :ntext AND nphoto = :nphoto" 


If I copy the query and paste it in myphpadmin the query will run binding the params.



This is the output if I run var_dump($query_result):



 bool(true) if I use print_r($query_result) I get "1"


This passes my if(!$query_result) test



If I run var_dump($record) or var_dump($query_result) I get nothing. It seems as if $query_result, because it is a bool, has no array to pass to $record.Therefore, there is nothing to convert to an object.I am at a loss here. Is it my PDO binding?










share|improve this question



















  • 3





    It looks like you're returning prematurely from your function. You have return $query_result; in your find_by_sql() function, but then you have code after your return statement.

    – bassxzero
    Mar 7 at 15:19






  • 1





    Also, you need to fetch and return a row of data, not a pdo statement. $row = $query_result->fetch(PDO::FETCH_ASSOC); return $row;

    – bassxzero
    Mar 7 at 15:21











  • I am attempting to store the result of the PDO $stmt in the new variable $query_result. If I do not return $query_result, then I end up with Call to a member function fetchAll() on boolean. Where should I return from the function?

    – Wes Henderson
    Mar 7 at 15:26











  • Isn't that what I am doing here "while($record = $query_result->fetchAll())" in my loop?

    – Wes Henderson
    Mar 7 at 15:28











  • If I strip the class down to just the pdo, I still get a boolean error.

    – Wes Henderson
    Mar 7 at 15:43















1















I am working to create a content class which will pull all content from the database via a PDO, then run the results through a method which will convert the results into objects, and the loop through the objects, and echo the object to a specific module of the webpage.



What is expected



When the class is activated, there will be an instance created via a PDO that will retrieve the needed data from the mysql database. Then this information will echo out and display on the webpage.



What is happening



I end up with no errors and the boolean number "1" where content should be. At first I thought this was an sql error. I get the same result "1" if I use print_r($query_result). See my tests below.



My class code is below



 <?php


class Content

// --- START OF ACTIVE RECORD CODE ---

public $n_id;
public $n_name;
public $n_text;
public $n_photo;

// Instantiating a STATIC Database Connection for the class to use
static protected $dbconnect;

static public function database($dbconnect)
self::$dbconnect = $dbconnect;

// constructing arguments

public function __construct($args=[])

$this->n_id = $args['n_id'] ?? '';
$this->n_name = $args['n_name'] ?? '';
$this->n_text = $args['n_text'] ?? '';
$this->n_photo = $args['n_photo'] ?? '';


// Multi use method to pass in sql that will execute the PDO only two parameters are bound ID and contentText.
static public function find_by_sql($sql)

// -------------BEGIN PDO-----------

// preparing PDO by loading sql, calling db connection, and storing in variable $stmt

$stmt = self::$dbconnect->prepare($sql);
// Binding Parameters for sql
$stmt->bindParam(':nid', $n_id, PDO::PARAM_INT);
$stmt->bindParam(':nall', $n_name, PDO::PARAM_STR);
$stmt->bindParam(':ntext', $n_text, PDO::PARAM_STR);
$stmt->bindParam(':nphoto', $n_photo, PDO::PARAM_INT);
// executing $stmt PDO and storing the result in $stmt
$query_result = $stmt->execute();
return $query_result;
// clearing the PDO after information is stored in $record
$stmt->closeCursor();


// ------------END PDO ----------

// Checking to see if a result exist. If nop result is stored in $stmt, then it will echo "Database query failed."
if(!$query_result)
exit("Query doesn't exist.");

// -------- BEGIN TURNING RESULTS INTO OBJECTS --------
$object_array = [];

// The result $stmt will be stored in the variable $record

while($record = $query_result->fetchAll())

// Taking $record and passing it to the static method instantiate() - see below. This method will return the $object_array.

$object_array[] = self::instantiate($record);



return $object_array;

// ------------ END TURNING RESULTS INTO OBJECTS --------


// method to test passing $sql to method find_all_sql();

static public function find_all()

$sql = "SELECT * FROM nmain WHERE nid = :id AND nall = :nall AND ntext = :ntext AND nphoto = :nphoto";
return self::find_by_sql($sql);



// --- BEGIN INSTANTIATE METHOD TO CREATE OBJECTS ---

static protected function instantiate($record)
$object = new self;
// Auto assign values
foreach($record as $property => $value)
if(property_exists($object, $property))
$object->$property = $value;


return $object;

// ----- END INSTANTIATE OF RECORD TO CREATE OBJECTS ---

// ---END OF ACTIVE RECORD CODE---



?>

**On my html webpage:**

$contents = Content::find_all();
foreach ((array) $contents as $content)
echo $content;



What I have tested



This is the output I get when I run var_dump($stmt);



object(PDOStatement)#3 (1) ["queryString"]=> string(119) "SELECT * FROM ndb WHERE id = :id AND nall = :nall AND ntext = :ntext AND nphoto = :nphoto" 


If I copy the query and paste it in myphpadmin the query will run binding the params.



This is the output if I run var_dump($query_result):



 bool(true) if I use print_r($query_result) I get "1"


This passes my if(!$query_result) test



If I run var_dump($record) or var_dump($query_result) I get nothing. It seems as if $query_result, because it is a bool, has no array to pass to $record.Therefore, there is nothing to convert to an object.I am at a loss here. Is it my PDO binding?










share|improve this question



















  • 3





    It looks like you're returning prematurely from your function. You have return $query_result; in your find_by_sql() function, but then you have code after your return statement.

    – bassxzero
    Mar 7 at 15:19






  • 1





    Also, you need to fetch and return a row of data, not a pdo statement. $row = $query_result->fetch(PDO::FETCH_ASSOC); return $row;

    – bassxzero
    Mar 7 at 15:21











  • I am attempting to store the result of the PDO $stmt in the new variable $query_result. If I do not return $query_result, then I end up with Call to a member function fetchAll() on boolean. Where should I return from the function?

    – Wes Henderson
    Mar 7 at 15:26











  • Isn't that what I am doing here "while($record = $query_result->fetchAll())" in my loop?

    – Wes Henderson
    Mar 7 at 15:28











  • If I strip the class down to just the pdo, I still get a boolean error.

    – Wes Henderson
    Mar 7 at 15:43













1












1








1


1






I am working to create a content class which will pull all content from the database via a PDO, then run the results through a method which will convert the results into objects, and the loop through the objects, and echo the object to a specific module of the webpage.



What is expected



When the class is activated, there will be an instance created via a PDO that will retrieve the needed data from the mysql database. Then this information will echo out and display on the webpage.



What is happening



I end up with no errors and the boolean number "1" where content should be. At first I thought this was an sql error. I get the same result "1" if I use print_r($query_result). See my tests below.



My class code is below



 <?php


class Content

// --- START OF ACTIVE RECORD CODE ---

public $n_id;
public $n_name;
public $n_text;
public $n_photo;

// Instantiating a STATIC Database Connection for the class to use
static protected $dbconnect;

static public function database($dbconnect)
self::$dbconnect = $dbconnect;

// constructing arguments

public function __construct($args=[])

$this->n_id = $args['n_id'] ?? '';
$this->n_name = $args['n_name'] ?? '';
$this->n_text = $args['n_text'] ?? '';
$this->n_photo = $args['n_photo'] ?? '';


// Multi use method to pass in sql that will execute the PDO only two parameters are bound ID and contentText.
static public function find_by_sql($sql)

// -------------BEGIN PDO-----------

// preparing PDO by loading sql, calling db connection, and storing in variable $stmt

$stmt = self::$dbconnect->prepare($sql);
// Binding Parameters for sql
$stmt->bindParam(':nid', $n_id, PDO::PARAM_INT);
$stmt->bindParam(':nall', $n_name, PDO::PARAM_STR);
$stmt->bindParam(':ntext', $n_text, PDO::PARAM_STR);
$stmt->bindParam(':nphoto', $n_photo, PDO::PARAM_INT);
// executing $stmt PDO and storing the result in $stmt
$query_result = $stmt->execute();
return $query_result;
// clearing the PDO after information is stored in $record
$stmt->closeCursor();


// ------------END PDO ----------

// Checking to see if a result exist. If nop result is stored in $stmt, then it will echo "Database query failed."
if(!$query_result)
exit("Query doesn't exist.");

// -------- BEGIN TURNING RESULTS INTO OBJECTS --------
$object_array = [];

// The result $stmt will be stored in the variable $record

while($record = $query_result->fetchAll())

// Taking $record and passing it to the static method instantiate() - see below. This method will return the $object_array.

$object_array[] = self::instantiate($record);



return $object_array;

// ------------ END TURNING RESULTS INTO OBJECTS --------


// method to test passing $sql to method find_all_sql();

static public function find_all()

$sql = "SELECT * FROM nmain WHERE nid = :id AND nall = :nall AND ntext = :ntext AND nphoto = :nphoto";
return self::find_by_sql($sql);



// --- BEGIN INSTANTIATE METHOD TO CREATE OBJECTS ---

static protected function instantiate($record)
$object = new self;
// Auto assign values
foreach($record as $property => $value)
if(property_exists($object, $property))
$object->$property = $value;


return $object;

// ----- END INSTANTIATE OF RECORD TO CREATE OBJECTS ---

// ---END OF ACTIVE RECORD CODE---



?>

**On my html webpage:**

$contents = Content::find_all();
foreach ((array) $contents as $content)
echo $content;



What I have tested



This is the output I get when I run var_dump($stmt);



object(PDOStatement)#3 (1) ["queryString"]=> string(119) "SELECT * FROM ndb WHERE id = :id AND nall = :nall AND ntext = :ntext AND nphoto = :nphoto" 


If I copy the query and paste it in myphpadmin the query will run binding the params.



This is the output if I run var_dump($query_result):



 bool(true) if I use print_r($query_result) I get "1"


This passes my if(!$query_result) test



If I run var_dump($record) or var_dump($query_result) I get nothing. It seems as if $query_result, because it is a bool, has no array to pass to $record.Therefore, there is nothing to convert to an object.I am at a loss here. Is it my PDO binding?










share|improve this question
















I am working to create a content class which will pull all content from the database via a PDO, then run the results through a method which will convert the results into objects, and the loop through the objects, and echo the object to a specific module of the webpage.



What is expected



When the class is activated, there will be an instance created via a PDO that will retrieve the needed data from the mysql database. Then this information will echo out and display on the webpage.



What is happening



I end up with no errors and the boolean number "1" where content should be. At first I thought this was an sql error. I get the same result "1" if I use print_r($query_result). See my tests below.



My class code is below



 <?php


class Content

// --- START OF ACTIVE RECORD CODE ---

public $n_id;
public $n_name;
public $n_text;
public $n_photo;

// Instantiating a STATIC Database Connection for the class to use
static protected $dbconnect;

static public function database($dbconnect)
self::$dbconnect = $dbconnect;

// constructing arguments

public function __construct($args=[])

$this->n_id = $args['n_id'] ?? '';
$this->n_name = $args['n_name'] ?? '';
$this->n_text = $args['n_text'] ?? '';
$this->n_photo = $args['n_photo'] ?? '';


// Multi use method to pass in sql that will execute the PDO only two parameters are bound ID and contentText.
static public function find_by_sql($sql)

// -------------BEGIN PDO-----------

// preparing PDO by loading sql, calling db connection, and storing in variable $stmt

$stmt = self::$dbconnect->prepare($sql);
// Binding Parameters for sql
$stmt->bindParam(':nid', $n_id, PDO::PARAM_INT);
$stmt->bindParam(':nall', $n_name, PDO::PARAM_STR);
$stmt->bindParam(':ntext', $n_text, PDO::PARAM_STR);
$stmt->bindParam(':nphoto', $n_photo, PDO::PARAM_INT);
// executing $stmt PDO and storing the result in $stmt
$query_result = $stmt->execute();
return $query_result;
// clearing the PDO after information is stored in $record
$stmt->closeCursor();


// ------------END PDO ----------

// Checking to see if a result exist. If nop result is stored in $stmt, then it will echo "Database query failed."
if(!$query_result)
exit("Query doesn't exist.");

// -------- BEGIN TURNING RESULTS INTO OBJECTS --------
$object_array = [];

// The result $stmt will be stored in the variable $record

while($record = $query_result->fetchAll())

// Taking $record and passing it to the static method instantiate() - see below. This method will return the $object_array.

$object_array[] = self::instantiate($record);



return $object_array;

// ------------ END TURNING RESULTS INTO OBJECTS --------


// method to test passing $sql to method find_all_sql();

static public function find_all()

$sql = "SELECT * FROM nmain WHERE nid = :id AND nall = :nall AND ntext = :ntext AND nphoto = :nphoto";
return self::find_by_sql($sql);



// --- BEGIN INSTANTIATE METHOD TO CREATE OBJECTS ---

static protected function instantiate($record)
$object = new self;
// Auto assign values
foreach($record as $property => $value)
if(property_exists($object, $property))
$object->$property = $value;


return $object;

// ----- END INSTANTIATE OF RECORD TO CREATE OBJECTS ---

// ---END OF ACTIVE RECORD CODE---



?>

**On my html webpage:**

$contents = Content::find_all();
foreach ((array) $contents as $content)
echo $content;



What I have tested



This is the output I get when I run var_dump($stmt);



object(PDOStatement)#3 (1) ["queryString"]=> string(119) "SELECT * FROM ndb WHERE id = :id AND nall = :nall AND ntext = :ntext AND nphoto = :nphoto" 


If I copy the query and paste it in myphpadmin the query will run binding the params.



This is the output if I run var_dump($query_result):



 bool(true) if I use print_r($query_result) I get "1"


This passes my if(!$query_result) test



If I run var_dump($record) or var_dump($query_result) I get nothing. It seems as if $query_result, because it is a bool, has no array to pass to $record.Therefore, there is nothing to convert to an object.I am at a loss here. Is it my PDO binding?







php mysql sql pdo boolean






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 7 at 15:17









jarlh

29.8k52138




29.8k52138










asked Mar 7 at 15:14









Wes HendersonWes Henderson

155




155







  • 3





    It looks like you're returning prematurely from your function. You have return $query_result; in your find_by_sql() function, but then you have code after your return statement.

    – bassxzero
    Mar 7 at 15:19






  • 1





    Also, you need to fetch and return a row of data, not a pdo statement. $row = $query_result->fetch(PDO::FETCH_ASSOC); return $row;

    – bassxzero
    Mar 7 at 15:21











  • I am attempting to store the result of the PDO $stmt in the new variable $query_result. If I do not return $query_result, then I end up with Call to a member function fetchAll() on boolean. Where should I return from the function?

    – Wes Henderson
    Mar 7 at 15:26











  • Isn't that what I am doing here "while($record = $query_result->fetchAll())" in my loop?

    – Wes Henderson
    Mar 7 at 15:28











  • If I strip the class down to just the pdo, I still get a boolean error.

    – Wes Henderson
    Mar 7 at 15:43












  • 3





    It looks like you're returning prematurely from your function. You have return $query_result; in your find_by_sql() function, but then you have code after your return statement.

    – bassxzero
    Mar 7 at 15:19






  • 1





    Also, you need to fetch and return a row of data, not a pdo statement. $row = $query_result->fetch(PDO::FETCH_ASSOC); return $row;

    – bassxzero
    Mar 7 at 15:21











  • I am attempting to store the result of the PDO $stmt in the new variable $query_result. If I do not return $query_result, then I end up with Call to a member function fetchAll() on boolean. Where should I return from the function?

    – Wes Henderson
    Mar 7 at 15:26











  • Isn't that what I am doing here "while($record = $query_result->fetchAll())" in my loop?

    – Wes Henderson
    Mar 7 at 15:28











  • If I strip the class down to just the pdo, I still get a boolean error.

    – Wes Henderson
    Mar 7 at 15:43







3




3





It looks like you're returning prematurely from your function. You have return $query_result; in your find_by_sql() function, but then you have code after your return statement.

– bassxzero
Mar 7 at 15:19





It looks like you're returning prematurely from your function. You have return $query_result; in your find_by_sql() function, but then you have code after your return statement.

– bassxzero
Mar 7 at 15:19




1




1





Also, you need to fetch and return a row of data, not a pdo statement. $row = $query_result->fetch(PDO::FETCH_ASSOC); return $row;

– bassxzero
Mar 7 at 15:21





Also, you need to fetch and return a row of data, not a pdo statement. $row = $query_result->fetch(PDO::FETCH_ASSOC); return $row;

– bassxzero
Mar 7 at 15:21













I am attempting to store the result of the PDO $stmt in the new variable $query_result. If I do not return $query_result, then I end up with Call to a member function fetchAll() on boolean. Where should I return from the function?

– Wes Henderson
Mar 7 at 15:26





I am attempting to store the result of the PDO $stmt in the new variable $query_result. If I do not return $query_result, then I end up with Call to a member function fetchAll() on boolean. Where should I return from the function?

– Wes Henderson
Mar 7 at 15:26













Isn't that what I am doing here "while($record = $query_result->fetchAll())" in my loop?

– Wes Henderson
Mar 7 at 15:28





Isn't that what I am doing here "while($record = $query_result->fetchAll())" in my loop?

– Wes Henderson
Mar 7 at 15:28













If I strip the class down to just the pdo, I still get a boolean error.

– Wes Henderson
Mar 7 at 15:43





If I strip the class down to just the pdo, I still get a boolean error.

– Wes Henderson
Mar 7 at 15:43












1 Answer
1






active

oldest

votes


















0














Your fetch should be on the statement and not the result of the execute (which is just to say the execute has succeeded or failed), also fetchAll will attempt to return all records, what you most likely want is fetch to process 1 record at a time. So you should have something like...



while($record = $stmt->fetch()) {


You can now remove the earlier return which is stopping further processing.






share|improve this answer























  • Thanks for the repsonse. The issue is still a boolean return from the PDO "Fatal error: Uncaught Error: Call to a member function fetch() on boolean"

    – Wes Henderson
    Mar 7 at 15:54











  • Just noticed the $stmt->closeCursor(); which you shouldn't need normally. So try commenting that out.

    – Nigel Ren
    Mar 7 at 15:56











  • Still no change.

    – Wes Henderson
    Mar 7 at 16:00











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55047121%2fpdo-expeced-array-not-returning-only-a-boolean-of-1-on-webpage%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Your fetch should be on the statement and not the result of the execute (which is just to say the execute has succeeded or failed), also fetchAll will attempt to return all records, what you most likely want is fetch to process 1 record at a time. So you should have something like...



while($record = $stmt->fetch()) {


You can now remove the earlier return which is stopping further processing.






share|improve this answer























  • Thanks for the repsonse. The issue is still a boolean return from the PDO "Fatal error: Uncaught Error: Call to a member function fetch() on boolean"

    – Wes Henderson
    Mar 7 at 15:54











  • Just noticed the $stmt->closeCursor(); which you shouldn't need normally. So try commenting that out.

    – Nigel Ren
    Mar 7 at 15:56











  • Still no change.

    – Wes Henderson
    Mar 7 at 16:00















0














Your fetch should be on the statement and not the result of the execute (which is just to say the execute has succeeded or failed), also fetchAll will attempt to return all records, what you most likely want is fetch to process 1 record at a time. So you should have something like...



while($record = $stmt->fetch()) {


You can now remove the earlier return which is stopping further processing.






share|improve this answer























  • Thanks for the repsonse. The issue is still a boolean return from the PDO "Fatal error: Uncaught Error: Call to a member function fetch() on boolean"

    – Wes Henderson
    Mar 7 at 15:54











  • Just noticed the $stmt->closeCursor(); which you shouldn't need normally. So try commenting that out.

    – Nigel Ren
    Mar 7 at 15:56











  • Still no change.

    – Wes Henderson
    Mar 7 at 16:00













0












0








0







Your fetch should be on the statement and not the result of the execute (which is just to say the execute has succeeded or failed), also fetchAll will attempt to return all records, what you most likely want is fetch to process 1 record at a time. So you should have something like...



while($record = $stmt->fetch()) {


You can now remove the earlier return which is stopping further processing.






share|improve this answer













Your fetch should be on the statement and not the result of the execute (which is just to say the execute has succeeded or failed), also fetchAll will attempt to return all records, what you most likely want is fetch to process 1 record at a time. So you should have something like...



while($record = $stmt->fetch()) {


You can now remove the earlier return which is stopping further processing.







share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 7 at 15:43









Nigel RenNigel Ren

28.3k62034




28.3k62034












  • Thanks for the repsonse. The issue is still a boolean return from the PDO "Fatal error: Uncaught Error: Call to a member function fetch() on boolean"

    – Wes Henderson
    Mar 7 at 15:54











  • Just noticed the $stmt->closeCursor(); which you shouldn't need normally. So try commenting that out.

    – Nigel Ren
    Mar 7 at 15:56











  • Still no change.

    – Wes Henderson
    Mar 7 at 16:00

















  • Thanks for the repsonse. The issue is still a boolean return from the PDO "Fatal error: Uncaught Error: Call to a member function fetch() on boolean"

    – Wes Henderson
    Mar 7 at 15:54











  • Just noticed the $stmt->closeCursor(); which you shouldn't need normally. So try commenting that out.

    – Nigel Ren
    Mar 7 at 15:56











  • Still no change.

    – Wes Henderson
    Mar 7 at 16:00
















Thanks for the repsonse. The issue is still a boolean return from the PDO "Fatal error: Uncaught Error: Call to a member function fetch() on boolean"

– Wes Henderson
Mar 7 at 15:54





Thanks for the repsonse. The issue is still a boolean return from the PDO "Fatal error: Uncaught Error: Call to a member function fetch() on boolean"

– Wes Henderson
Mar 7 at 15:54













Just noticed the $stmt->closeCursor(); which you shouldn't need normally. So try commenting that out.

– Nigel Ren
Mar 7 at 15:56





Just noticed the $stmt->closeCursor(); which you shouldn't need normally. So try commenting that out.

– Nigel Ren
Mar 7 at 15:56













Still no change.

– Wes Henderson
Mar 7 at 16:00





Still no change.

– Wes Henderson
Mar 7 at 16:00



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55047121%2fpdo-expeced-array-not-returning-only-a-boolean-of-1-on-webpage%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

1928 у кіно

Захаров Федір Захарович

Ель Греко