setFetchMode PDO::FETCH_CLASS PDO::FETCH_PROPS_LATE return undefined












-1















I'm trying to use:



$stmt>setFetchMode(PDO::FETCH_CLASS|PDO::FETCH_PROPS_LATE,static::MODEL_CLASS);         
$customer = $stmt->fetch();`


To bind the data coming back into the constructor that's associated to static::MODEL_CLASS. Even if I just type the actual classname 'Customer' I get the error down here. Before the code gets the chance to fetch it goes into error. Without the setFetchMode i get data back. The database and model have the exact same properties in the exact same order. Does anyone know what is going on???



Error:




( ! ) Fatal error: Uncaught ArgumentCountError: Too few arguments to
function Klant::__construct(), 0 passed and exactly 8 expected in
D:DocumentsStackDropboxDropboxDeltionworkingHoofdstuk
6datamapperdesignpattern.php on line 14




class Klant {
public $ID;
public $voornaam;
public $achternaam;
public $adres;
public $postcode;
public $woonplaats;
public $email;
public $password;

public function __construct($ID, $voornaam, $achternaam, $adres, $postcode, $woonplaats, $email, $password) {
$this->ID = $ID;
$this->voornaam = $voornaam;
$this->achternaam = $achternaam;
$this->adres = $adres;
$this->postcode = $postcode;
$this->woonplaats = $woonplaats;
$this->email = $email;
$this->password = $password;
}
function read($ID)
{
$stmt = $this->pdo->prepare("SELECT * FROM customer WHERE ID = ?");
try {
$stmt->bindParam(1, $ID);
$stmt->execute();
}
catch(PDOException $e) {
echo $e;
}
$stmt->setFetchMode(PDO::FETCH_CLASS|PDO::FETCH_PROPS_LATE,static::MODEL_CLASS);
$customer = $stmt->fetch();
return $customer;
}


^ Full code for reference. The constructor is a normal public function __construct()



IMPORTANT? NOTE:
This same exact code and this same exact database works with someone else. I have a fresh installation of Xampp. And the PHP version is 7.2.11.










share|improve this question

























  • "The constructor is a normal public function __constructor()" - The word is __construct and not __constructor. Ref: php.net/manual/en/language.oop5.decon.php - I don't understand what you meant by that though. Where is the code for it?

    – Funk Forty Niner
    Nov 14 '18 at 23:23













  • @miken32 I noticed the edit; the OP's question is unclear. I don't know why they wrote what they wrote as quoted in my comment above. The question is unclear for me in that respect.

    – Funk Forty Niner
    Nov 14 '18 at 23:48








  • 1





    @FunkFortyNiner Based on the error message which specifically mentions "Klant::__construct()", I assume 'constructor' was just a typo and the function is named correctly, but it has 8 arguments, not none as they suggested.

    – miken32
    Nov 14 '18 at 23:51













  • @miken32 That's what I'm not sure about. Maybe they only wrote that as a way to explain they're using a constructor. I've seen questions before where they used __constructor instead of __construct, that's why.

    – Funk Forty Niner
    Nov 14 '18 at 23:52


















-1















I'm trying to use:



$stmt>setFetchMode(PDO::FETCH_CLASS|PDO::FETCH_PROPS_LATE,static::MODEL_CLASS);         
$customer = $stmt->fetch();`


To bind the data coming back into the constructor that's associated to static::MODEL_CLASS. Even if I just type the actual classname 'Customer' I get the error down here. Before the code gets the chance to fetch it goes into error. Without the setFetchMode i get data back. The database and model have the exact same properties in the exact same order. Does anyone know what is going on???



Error:




( ! ) Fatal error: Uncaught ArgumentCountError: Too few arguments to
function Klant::__construct(), 0 passed and exactly 8 expected in
D:DocumentsStackDropboxDropboxDeltionworkingHoofdstuk
6datamapperdesignpattern.php on line 14




class Klant {
public $ID;
public $voornaam;
public $achternaam;
public $adres;
public $postcode;
public $woonplaats;
public $email;
public $password;

public function __construct($ID, $voornaam, $achternaam, $adres, $postcode, $woonplaats, $email, $password) {
$this->ID = $ID;
$this->voornaam = $voornaam;
$this->achternaam = $achternaam;
$this->adres = $adres;
$this->postcode = $postcode;
$this->woonplaats = $woonplaats;
$this->email = $email;
$this->password = $password;
}
function read($ID)
{
$stmt = $this->pdo->prepare("SELECT * FROM customer WHERE ID = ?");
try {
$stmt->bindParam(1, $ID);
$stmt->execute();
}
catch(PDOException $e) {
echo $e;
}
$stmt->setFetchMode(PDO::FETCH_CLASS|PDO::FETCH_PROPS_LATE,static::MODEL_CLASS);
$customer = $stmt->fetch();
return $customer;
}


^ Full code for reference. The constructor is a normal public function __construct()



IMPORTANT? NOTE:
This same exact code and this same exact database works with someone else. I have a fresh installation of Xampp. And the PHP version is 7.2.11.










share|improve this question

























  • "The constructor is a normal public function __constructor()" - The word is __construct and not __constructor. Ref: php.net/manual/en/language.oop5.decon.php - I don't understand what you meant by that though. Where is the code for it?

    – Funk Forty Niner
    Nov 14 '18 at 23:23













  • @miken32 I noticed the edit; the OP's question is unclear. I don't know why they wrote what they wrote as quoted in my comment above. The question is unclear for me in that respect.

    – Funk Forty Niner
    Nov 14 '18 at 23:48








  • 1





    @FunkFortyNiner Based on the error message which specifically mentions "Klant::__construct()", I assume 'constructor' was just a typo and the function is named correctly, but it has 8 arguments, not none as they suggested.

    – miken32
    Nov 14 '18 at 23:51













  • @miken32 That's what I'm not sure about. Maybe they only wrote that as a way to explain they're using a constructor. I've seen questions before where they used __constructor instead of __construct, that's why.

    – Funk Forty Niner
    Nov 14 '18 at 23:52
















-1












-1








-1








I'm trying to use:



$stmt>setFetchMode(PDO::FETCH_CLASS|PDO::FETCH_PROPS_LATE,static::MODEL_CLASS);         
$customer = $stmt->fetch();`


To bind the data coming back into the constructor that's associated to static::MODEL_CLASS. Even if I just type the actual classname 'Customer' I get the error down here. Before the code gets the chance to fetch it goes into error. Without the setFetchMode i get data back. The database and model have the exact same properties in the exact same order. Does anyone know what is going on???



Error:




( ! ) Fatal error: Uncaught ArgumentCountError: Too few arguments to
function Klant::__construct(), 0 passed and exactly 8 expected in
D:DocumentsStackDropboxDropboxDeltionworkingHoofdstuk
6datamapperdesignpattern.php on line 14




class Klant {
public $ID;
public $voornaam;
public $achternaam;
public $adres;
public $postcode;
public $woonplaats;
public $email;
public $password;

public function __construct($ID, $voornaam, $achternaam, $adres, $postcode, $woonplaats, $email, $password) {
$this->ID = $ID;
$this->voornaam = $voornaam;
$this->achternaam = $achternaam;
$this->adres = $adres;
$this->postcode = $postcode;
$this->woonplaats = $woonplaats;
$this->email = $email;
$this->password = $password;
}
function read($ID)
{
$stmt = $this->pdo->prepare("SELECT * FROM customer WHERE ID = ?");
try {
$stmt->bindParam(1, $ID);
$stmt->execute();
}
catch(PDOException $e) {
echo $e;
}
$stmt->setFetchMode(PDO::FETCH_CLASS|PDO::FETCH_PROPS_LATE,static::MODEL_CLASS);
$customer = $stmt->fetch();
return $customer;
}


^ Full code for reference. The constructor is a normal public function __construct()



IMPORTANT? NOTE:
This same exact code and this same exact database works with someone else. I have a fresh installation of Xampp. And the PHP version is 7.2.11.










share|improve this question
















I'm trying to use:



$stmt>setFetchMode(PDO::FETCH_CLASS|PDO::FETCH_PROPS_LATE,static::MODEL_CLASS);         
$customer = $stmt->fetch();`


To bind the data coming back into the constructor that's associated to static::MODEL_CLASS. Even if I just type the actual classname 'Customer' I get the error down here. Before the code gets the chance to fetch it goes into error. Without the setFetchMode i get data back. The database and model have the exact same properties in the exact same order. Does anyone know what is going on???



Error:




( ! ) Fatal error: Uncaught ArgumentCountError: Too few arguments to
function Klant::__construct(), 0 passed and exactly 8 expected in
D:DocumentsStackDropboxDropboxDeltionworkingHoofdstuk
6datamapperdesignpattern.php on line 14




class Klant {
public $ID;
public $voornaam;
public $achternaam;
public $adres;
public $postcode;
public $woonplaats;
public $email;
public $password;

public function __construct($ID, $voornaam, $achternaam, $adres, $postcode, $woonplaats, $email, $password) {
$this->ID = $ID;
$this->voornaam = $voornaam;
$this->achternaam = $achternaam;
$this->adres = $adres;
$this->postcode = $postcode;
$this->woonplaats = $woonplaats;
$this->email = $email;
$this->password = $password;
}
function read($ID)
{
$stmt = $this->pdo->prepare("SELECT * FROM customer WHERE ID = ?");
try {
$stmt->bindParam(1, $ID);
$stmt->execute();
}
catch(PDOException $e) {
echo $e;
}
$stmt->setFetchMode(PDO::FETCH_CLASS|PDO::FETCH_PROPS_LATE,static::MODEL_CLASS);
$customer = $stmt->fetch();
return $customer;
}


^ Full code for reference. The constructor is a normal public function __construct()



IMPORTANT? NOTE:
This same exact code and this same exact database works with someone else. I have a fresh installation of Xampp. And the PHP version is 7.2.11.







php mysql pdo






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 15 '18 at 17:57







Carlove

















asked Nov 14 '18 at 22:45









CarloveCarlove

548




548













  • "The constructor is a normal public function __constructor()" - The word is __construct and not __constructor. Ref: php.net/manual/en/language.oop5.decon.php - I don't understand what you meant by that though. Where is the code for it?

    – Funk Forty Niner
    Nov 14 '18 at 23:23













  • @miken32 I noticed the edit; the OP's question is unclear. I don't know why they wrote what they wrote as quoted in my comment above. The question is unclear for me in that respect.

    – Funk Forty Niner
    Nov 14 '18 at 23:48








  • 1





    @FunkFortyNiner Based on the error message which specifically mentions "Klant::__construct()", I assume 'constructor' was just a typo and the function is named correctly, but it has 8 arguments, not none as they suggested.

    – miken32
    Nov 14 '18 at 23:51













  • @miken32 That's what I'm not sure about. Maybe they only wrote that as a way to explain they're using a constructor. I've seen questions before where they used __constructor instead of __construct, that's why.

    – Funk Forty Niner
    Nov 14 '18 at 23:52





















  • "The constructor is a normal public function __constructor()" - The word is __construct and not __constructor. Ref: php.net/manual/en/language.oop5.decon.php - I don't understand what you meant by that though. Where is the code for it?

    – Funk Forty Niner
    Nov 14 '18 at 23:23













  • @miken32 I noticed the edit; the OP's question is unclear. I don't know why they wrote what they wrote as quoted in my comment above. The question is unclear for me in that respect.

    – Funk Forty Niner
    Nov 14 '18 at 23:48








  • 1





    @FunkFortyNiner Based on the error message which specifically mentions "Klant::__construct()", I assume 'constructor' was just a typo and the function is named correctly, but it has 8 arguments, not none as they suggested.

    – miken32
    Nov 14 '18 at 23:51













  • @miken32 That's what I'm not sure about. Maybe they only wrote that as a way to explain they're using a constructor. I've seen questions before where they used __constructor instead of __construct, that's why.

    – Funk Forty Niner
    Nov 14 '18 at 23:52



















"The constructor is a normal public function __constructor()" - The word is __construct and not __constructor. Ref: php.net/manual/en/language.oop5.decon.php - I don't understand what you meant by that though. Where is the code for it?

– Funk Forty Niner
Nov 14 '18 at 23:23







"The constructor is a normal public function __constructor()" - The word is __construct and not __constructor. Ref: php.net/manual/en/language.oop5.decon.php - I don't understand what you meant by that though. Where is the code for it?

– Funk Forty Niner
Nov 14 '18 at 23:23















@miken32 I noticed the edit; the OP's question is unclear. I don't know why they wrote what they wrote as quoted in my comment above. The question is unclear for me in that respect.

– Funk Forty Niner
Nov 14 '18 at 23:48







@miken32 I noticed the edit; the OP's question is unclear. I don't know why they wrote what they wrote as quoted in my comment above. The question is unclear for me in that respect.

– Funk Forty Niner
Nov 14 '18 at 23:48






1




1





@FunkFortyNiner Based on the error message which specifically mentions "Klant::__construct()", I assume 'constructor' was just a typo and the function is named correctly, but it has 8 arguments, not none as they suggested.

– miken32
Nov 14 '18 at 23:51







@FunkFortyNiner Based on the error message which specifically mentions "Klant::__construct()", I assume 'constructor' was just a typo and the function is named correctly, but it has 8 arguments, not none as they suggested.

– miken32
Nov 14 '18 at 23:51















@miken32 That's what I'm not sure about. Maybe they only wrote that as a way to explain they're using a constructor. I've seen questions before where they used __constructor instead of __construct, that's why.

– Funk Forty Niner
Nov 14 '18 at 23:52







@miken32 That's what I'm not sure about. Maybe they only wrote that as a way to explain they're using a constructor. I've seen questions before where they used __constructor instead of __construct, that's why.

– Funk Forty Niner
Nov 14 '18 at 23:52














1 Answer
1






active

oldest

votes


















1














PDO will not send arguments to your constructor. Instead you can create your object and then use PDO::FETCH_INTO to save into an already existing object.



<?php
function read($ID)
{
$stmt = $this->pdo->prepare("SELECT * FROM customer WHERE ID = ?");
try {
$stmt->bindParam(1, $ID);
$stmt->execute();
}
catch(PDOException $e) {
echo $e;
}
$customer = new Klant(...pass your desired arguments...);
$stmt->setFetchMode(PDO::FETCH_INTO, $customer);
$stmt->fetch();
return $customer;
}





share|improve this answer
























  • Yeah, thank you. I know it can be done this way, but I find it super annoying that the example code doesn't work. Even though the same code works with others. Is it a PHPMyAdmin (MySql) thing? Even though it's freshly installed and it reads data just fine.

    – Carlove
    Nov 15 '18 at 18:03













  • Does your object have public properties that match the names of the database columns?

    – miken32
    Nov 15 '18 at 18:08











  • Just tested and it works as expected for me: pastebin.com/e5sCn7PS

    – miken32
    Nov 15 '18 at 18:17











  • Yeha, that does work, thanks! But I was talking about the example from my book where they tell you to use fetch_class. But I guess my laptop is just being a turd or something.

    – Carlove
    Nov 15 '18 at 18:34











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%2f53309853%2fsetfetchmode-pdofetch-class-pdofetch-props-late-return-undefined%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









1














PDO will not send arguments to your constructor. Instead you can create your object and then use PDO::FETCH_INTO to save into an already existing object.



<?php
function read($ID)
{
$stmt = $this->pdo->prepare("SELECT * FROM customer WHERE ID = ?");
try {
$stmt->bindParam(1, $ID);
$stmt->execute();
}
catch(PDOException $e) {
echo $e;
}
$customer = new Klant(...pass your desired arguments...);
$stmt->setFetchMode(PDO::FETCH_INTO, $customer);
$stmt->fetch();
return $customer;
}





share|improve this answer
























  • Yeah, thank you. I know it can be done this way, but I find it super annoying that the example code doesn't work. Even though the same code works with others. Is it a PHPMyAdmin (MySql) thing? Even though it's freshly installed and it reads data just fine.

    – Carlove
    Nov 15 '18 at 18:03













  • Does your object have public properties that match the names of the database columns?

    – miken32
    Nov 15 '18 at 18:08











  • Just tested and it works as expected for me: pastebin.com/e5sCn7PS

    – miken32
    Nov 15 '18 at 18:17











  • Yeha, that does work, thanks! But I was talking about the example from my book where they tell you to use fetch_class. But I guess my laptop is just being a turd or something.

    – Carlove
    Nov 15 '18 at 18:34
















1














PDO will not send arguments to your constructor. Instead you can create your object and then use PDO::FETCH_INTO to save into an already existing object.



<?php
function read($ID)
{
$stmt = $this->pdo->prepare("SELECT * FROM customer WHERE ID = ?");
try {
$stmt->bindParam(1, $ID);
$stmt->execute();
}
catch(PDOException $e) {
echo $e;
}
$customer = new Klant(...pass your desired arguments...);
$stmt->setFetchMode(PDO::FETCH_INTO, $customer);
$stmt->fetch();
return $customer;
}





share|improve this answer
























  • Yeah, thank you. I know it can be done this way, but I find it super annoying that the example code doesn't work. Even though the same code works with others. Is it a PHPMyAdmin (MySql) thing? Even though it's freshly installed and it reads data just fine.

    – Carlove
    Nov 15 '18 at 18:03













  • Does your object have public properties that match the names of the database columns?

    – miken32
    Nov 15 '18 at 18:08











  • Just tested and it works as expected for me: pastebin.com/e5sCn7PS

    – miken32
    Nov 15 '18 at 18:17











  • Yeha, that does work, thanks! But I was talking about the example from my book where they tell you to use fetch_class. But I guess my laptop is just being a turd or something.

    – Carlove
    Nov 15 '18 at 18:34














1












1








1







PDO will not send arguments to your constructor. Instead you can create your object and then use PDO::FETCH_INTO to save into an already existing object.



<?php
function read($ID)
{
$stmt = $this->pdo->prepare("SELECT * FROM customer WHERE ID = ?");
try {
$stmt->bindParam(1, $ID);
$stmt->execute();
}
catch(PDOException $e) {
echo $e;
}
$customer = new Klant(...pass your desired arguments...);
$stmt->setFetchMode(PDO::FETCH_INTO, $customer);
$stmt->fetch();
return $customer;
}





share|improve this answer













PDO will not send arguments to your constructor. Instead you can create your object and then use PDO::FETCH_INTO to save into an already existing object.



<?php
function read($ID)
{
$stmt = $this->pdo->prepare("SELECT * FROM customer WHERE ID = ?");
try {
$stmt->bindParam(1, $ID);
$stmt->execute();
}
catch(PDOException $e) {
echo $e;
}
$customer = new Klant(...pass your desired arguments...);
$stmt->setFetchMode(PDO::FETCH_INTO, $customer);
$stmt->fetch();
return $customer;
}






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 14 '18 at 23:45









miken32miken32

24k84972




24k84972













  • Yeah, thank you. I know it can be done this way, but I find it super annoying that the example code doesn't work. Even though the same code works with others. Is it a PHPMyAdmin (MySql) thing? Even though it's freshly installed and it reads data just fine.

    – Carlove
    Nov 15 '18 at 18:03













  • Does your object have public properties that match the names of the database columns?

    – miken32
    Nov 15 '18 at 18:08











  • Just tested and it works as expected for me: pastebin.com/e5sCn7PS

    – miken32
    Nov 15 '18 at 18:17











  • Yeha, that does work, thanks! But I was talking about the example from my book where they tell you to use fetch_class. But I guess my laptop is just being a turd or something.

    – Carlove
    Nov 15 '18 at 18:34



















  • Yeah, thank you. I know it can be done this way, but I find it super annoying that the example code doesn't work. Even though the same code works with others. Is it a PHPMyAdmin (MySql) thing? Even though it's freshly installed and it reads data just fine.

    – Carlove
    Nov 15 '18 at 18:03













  • Does your object have public properties that match the names of the database columns?

    – miken32
    Nov 15 '18 at 18:08











  • Just tested and it works as expected for me: pastebin.com/e5sCn7PS

    – miken32
    Nov 15 '18 at 18:17











  • Yeha, that does work, thanks! But I was talking about the example from my book where they tell you to use fetch_class. But I guess my laptop is just being a turd or something.

    – Carlove
    Nov 15 '18 at 18:34

















Yeah, thank you. I know it can be done this way, but I find it super annoying that the example code doesn't work. Even though the same code works with others. Is it a PHPMyAdmin (MySql) thing? Even though it's freshly installed and it reads data just fine.

– Carlove
Nov 15 '18 at 18:03







Yeah, thank you. I know it can be done this way, but I find it super annoying that the example code doesn't work. Even though the same code works with others. Is it a PHPMyAdmin (MySql) thing? Even though it's freshly installed and it reads data just fine.

– Carlove
Nov 15 '18 at 18:03















Does your object have public properties that match the names of the database columns?

– miken32
Nov 15 '18 at 18:08





Does your object have public properties that match the names of the database columns?

– miken32
Nov 15 '18 at 18:08













Just tested and it works as expected for me: pastebin.com/e5sCn7PS

– miken32
Nov 15 '18 at 18:17





Just tested and it works as expected for me: pastebin.com/e5sCn7PS

– miken32
Nov 15 '18 at 18:17













Yeha, that does work, thanks! But I was talking about the example from my book where they tell you to use fetch_class. But I guess my laptop is just being a turd or something.

– Carlove
Nov 15 '18 at 18:34





Yeha, that does work, thanks! But I was talking about the example from my book where they tell you to use fetch_class. But I guess my laptop is just being a turd or something.

– Carlove
Nov 15 '18 at 18:34




















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%2f53309853%2fsetfetchmode-pdofetch-class-pdofetch-props-late-return-undefined%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

Florida Star v. B. J. F.

Danny Elfman

Lugert, Oklahoma