setFetchMode PDO::FETCH_CLASS PDO::FETCH_PROPS_LATE return undefined
up vote
-1
down vote
favorite
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
add a comment |
up vote
-1
down vote
favorite
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
"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 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 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 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 at 23:52
add a comment |
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
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
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
php mysql pdo
edited Nov 15 at 17:57
asked Nov 14 at 22:45
Carlove
498
498
"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 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 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 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 at 23:52
add a comment |
"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 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 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 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 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 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 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 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 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 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 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 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 at 23:52
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
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;
}
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 at 18:03
Does your object have public properties that match the names of the database columns?
– miken32
Nov 15 at 18:08
Just tested and it works as expected for me: pastebin.com/e5sCn7PS
– miken32
Nov 15 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 at 18:34
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
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;
}
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 at 18:03
Does your object have public properties that match the names of the database columns?
– miken32
Nov 15 at 18:08
Just tested and it works as expected for me: pastebin.com/e5sCn7PS
– miken32
Nov 15 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 at 18:34
add a comment |
up vote
1
down vote
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;
}
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 at 18:03
Does your object have public properties that match the names of the database columns?
– miken32
Nov 15 at 18:08
Just tested and it works as expected for me: pastebin.com/e5sCn7PS
– miken32
Nov 15 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 at 18:34
add a comment |
up vote
1
down vote
up vote
1
down vote
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;
}
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;
}
answered Nov 14 at 23:45
miken32
23k84671
23k84671
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 at 18:03
Does your object have public properties that match the names of the database columns?
– miken32
Nov 15 at 18:08
Just tested and it works as expected for me: pastebin.com/e5sCn7PS
– miken32
Nov 15 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 at 18:34
add a comment |
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 at 18:03
Does your object have public properties that match the names of the database columns?
– miken32
Nov 15 at 18:08
Just tested and it works as expected for me: pastebin.com/e5sCn7PS
– miken32
Nov 15 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 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 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 at 18:03
Does your object have public properties that match the names of the database columns?
– miken32
Nov 15 at 18:08
Does your object have public properties that match the names of the database columns?
– miken32
Nov 15 at 18:08
Just tested and it works as expected for me: pastebin.com/e5sCn7PS
– miken32
Nov 15 at 18:17
Just tested and it works as expected for me: pastebin.com/e5sCn7PS
– miken32
Nov 15 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 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 at 18:34
add a comment |
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
"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 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 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 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 at 23:52