What's wrong with mysqli::get_result?
I have the following code:
$postId = $_GET['postId'];
$mysqli = new mysqli('localhost', 'username', 'database', 'name_db');
mysqli_report(MYSQLI_REPORT_ALL);
$stmt = $mysqli->stmt_init();
$stmt->prepare("
SELECT *
FROM posts
WHERE postId = ?
");
$stmt->bind_param('i', $postId);
$stmt->execute();
$result = $stmt->get_result();//Call to undefined method
$info = $result->fetch_array(MYSQLI_ASSOC);
echo json_encode($info);
And I get some error marked above. What have i done wrong?
EDIT:
changed fecth_array() to fetch_array()
php mysqli
add a comment |
I have the following code:
$postId = $_GET['postId'];
$mysqli = new mysqli('localhost', 'username', 'database', 'name_db');
mysqli_report(MYSQLI_REPORT_ALL);
$stmt = $mysqli->stmt_init();
$stmt->prepare("
SELECT *
FROM posts
WHERE postId = ?
");
$stmt->bind_param('i', $postId);
$stmt->execute();
$result = $stmt->get_result();//Call to undefined method
$info = $result->fetch_array(MYSQLI_ASSOC);
echo json_encode($info);
And I get some error marked above. What have i done wrong?
EDIT:
changed fecth_array() to fetch_array()
php mysqli
add a comment |
I have the following code:
$postId = $_GET['postId'];
$mysqli = new mysqli('localhost', 'username', 'database', 'name_db');
mysqli_report(MYSQLI_REPORT_ALL);
$stmt = $mysqli->stmt_init();
$stmt->prepare("
SELECT *
FROM posts
WHERE postId = ?
");
$stmt->bind_param('i', $postId);
$stmt->execute();
$result = $stmt->get_result();//Call to undefined method
$info = $result->fetch_array(MYSQLI_ASSOC);
echo json_encode($info);
And I get some error marked above. What have i done wrong?
EDIT:
changed fecth_array() to fetch_array()
php mysqli
I have the following code:
$postId = $_GET['postId'];
$mysqli = new mysqli('localhost', 'username', 'database', 'name_db');
mysqli_report(MYSQLI_REPORT_ALL);
$stmt = $mysqli->stmt_init();
$stmt->prepare("
SELECT *
FROM posts
WHERE postId = ?
");
$stmt->bind_param('i', $postId);
$stmt->execute();
$result = $stmt->get_result();//Call to undefined method
$info = $result->fetch_array(MYSQLI_ASSOC);
echo json_encode($info);
And I get some error marked above. What have i done wrong?
EDIT:
changed fecth_array() to fetch_array()
php mysqli
php mysqli
edited Aug 20 '11 at 18:00
einstein
asked Aug 20 '11 at 17:55
einsteineinstein
5,758196997
5,758196997
add a comment |
add a comment |
6 Answers
6
active
oldest
votes
As others have stated, it is only available in bleeding edge PHP. You could do something like this (answer to a similar question):
function bind_array($stmt, &$row) {
$md = $stmt->result_metadata();
$params = array();
while($field = $md->fetch_field()) {
$params = &$row[$field->name];
}
call_user_func_array(array($stmt, 'bind_result'), $params);
}
// ....
bind_array($stmt, $info);
$stmt->fetch();
echo json_encode($info);
Or use mysqli::query if you have a simple query with no parameters - don't use it with dynamically generated SQL-statements.
10
Please don't recommend "downgrading" from prepared statements to bogstandard strings. It's hard enough getting people to go the other way.
– Lightness Races in Orbit
Aug 20 '11 at 18:22
@Tomalak Geret'kal: right - thanks for the reminder, I've added a disclaimer. Not sure if I should remove the reference completely.
– vstm
Aug 20 '11 at 18:33
I'm not sure either.
– Lightness Races in Orbit
Aug 20 '11 at 18:38
1
It is weird that "downgrading" is the only real option PHP gave us on some situations.
– Dan
Oct 8 '13 at 21:58
1
I tried to use wile stms->fetch() but it's skipping the first record. How can we loop over all result records?
– Lamar
Jun 5 '16 at 10:32
add a comment |
As mentioned in php documentation mysqli_stmt::get_result, this method is supported since PHP 5.3.0.
And it is stated in the user notes section that:
This method requires the mysqlnd driver. Othervise you will get this error: Call to undefined method mysqli_stmt::get_result()
add a comment |
You're probably using old version of PHP not supporting get_result() as stated on manual page
(No version information available, might only be in SVN)
This is right. It usually means there's no release with this function in.
– Lightness Races in Orbit
Aug 20 '11 at 18:19
add a comment |
The manual page doesn't give any clear information on which minimum version of PHP is needed for get_result() to work:
(No version information available, might only be in SVN)
I don't know the background to this, but it may simply not be available in your PHP version.
You could use fetch() instead.
Ok, I thinkt that might be the case. But can I ask how I can get rows in a result set using mysqli and prepared statements?
– einstein
Aug 20 '11 at 18:03
@Woho see my update
– Pekka 웃
Aug 20 '11 at 18:03
I don't like using fetch, because I have so much columns. Is there another way?
– einstein
Aug 20 '11 at 18:05
@Wohofetch_array()for example
– Pekka 웃
Aug 20 '11 at 18:07
add a comment |
I´m guessing it´s the line below that, change:
$info = $result->fecth_array(MYSQLI_ASSOC);
to:
$info = $result->fetch_array(MYSQLI_ASSOC);
ok changed that. But php issued an error before mysqli::fetch_array();
– einstein
Aug 20 '11 at 17:59
add a comment |
check to see it your PHP mysql native driver is enable. get->result() only works when mysql native driver is enable. http://www.php.net/manual/en/mysqli-stmt.get-result.php
add a comment |
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
});
}
});
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%2f7133575%2fwhats-wrong-with-mysqliget-result%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
6 Answers
6
active
oldest
votes
6 Answers
6
active
oldest
votes
active
oldest
votes
active
oldest
votes
As others have stated, it is only available in bleeding edge PHP. You could do something like this (answer to a similar question):
function bind_array($stmt, &$row) {
$md = $stmt->result_metadata();
$params = array();
while($field = $md->fetch_field()) {
$params = &$row[$field->name];
}
call_user_func_array(array($stmt, 'bind_result'), $params);
}
// ....
bind_array($stmt, $info);
$stmt->fetch();
echo json_encode($info);
Or use mysqli::query if you have a simple query with no parameters - don't use it with dynamically generated SQL-statements.
10
Please don't recommend "downgrading" from prepared statements to bogstandard strings. It's hard enough getting people to go the other way.
– Lightness Races in Orbit
Aug 20 '11 at 18:22
@Tomalak Geret'kal: right - thanks for the reminder, I've added a disclaimer. Not sure if I should remove the reference completely.
– vstm
Aug 20 '11 at 18:33
I'm not sure either.
– Lightness Races in Orbit
Aug 20 '11 at 18:38
1
It is weird that "downgrading" is the only real option PHP gave us on some situations.
– Dan
Oct 8 '13 at 21:58
1
I tried to use wile stms->fetch() but it's skipping the first record. How can we loop over all result records?
– Lamar
Jun 5 '16 at 10:32
add a comment |
As others have stated, it is only available in bleeding edge PHP. You could do something like this (answer to a similar question):
function bind_array($stmt, &$row) {
$md = $stmt->result_metadata();
$params = array();
while($field = $md->fetch_field()) {
$params = &$row[$field->name];
}
call_user_func_array(array($stmt, 'bind_result'), $params);
}
// ....
bind_array($stmt, $info);
$stmt->fetch();
echo json_encode($info);
Or use mysqli::query if you have a simple query with no parameters - don't use it with dynamically generated SQL-statements.
10
Please don't recommend "downgrading" from prepared statements to bogstandard strings. It's hard enough getting people to go the other way.
– Lightness Races in Orbit
Aug 20 '11 at 18:22
@Tomalak Geret'kal: right - thanks for the reminder, I've added a disclaimer. Not sure if I should remove the reference completely.
– vstm
Aug 20 '11 at 18:33
I'm not sure either.
– Lightness Races in Orbit
Aug 20 '11 at 18:38
1
It is weird that "downgrading" is the only real option PHP gave us on some situations.
– Dan
Oct 8 '13 at 21:58
1
I tried to use wile stms->fetch() but it's skipping the first record. How can we loop over all result records?
– Lamar
Jun 5 '16 at 10:32
add a comment |
As others have stated, it is only available in bleeding edge PHP. You could do something like this (answer to a similar question):
function bind_array($stmt, &$row) {
$md = $stmt->result_metadata();
$params = array();
while($field = $md->fetch_field()) {
$params = &$row[$field->name];
}
call_user_func_array(array($stmt, 'bind_result'), $params);
}
// ....
bind_array($stmt, $info);
$stmt->fetch();
echo json_encode($info);
Or use mysqli::query if you have a simple query with no parameters - don't use it with dynamically generated SQL-statements.
As others have stated, it is only available in bleeding edge PHP. You could do something like this (answer to a similar question):
function bind_array($stmt, &$row) {
$md = $stmt->result_metadata();
$params = array();
while($field = $md->fetch_field()) {
$params = &$row[$field->name];
}
call_user_func_array(array($stmt, 'bind_result'), $params);
}
// ....
bind_array($stmt, $info);
$stmt->fetch();
echo json_encode($info);
Or use mysqli::query if you have a simple query with no parameters - don't use it with dynamically generated SQL-statements.
edited May 23 '17 at 11:44
Community♦
11
11
answered Aug 20 '11 at 18:08
vstmvstm
10.6k13742
10.6k13742
10
Please don't recommend "downgrading" from prepared statements to bogstandard strings. It's hard enough getting people to go the other way.
– Lightness Races in Orbit
Aug 20 '11 at 18:22
@Tomalak Geret'kal: right - thanks for the reminder, I've added a disclaimer. Not sure if I should remove the reference completely.
– vstm
Aug 20 '11 at 18:33
I'm not sure either.
– Lightness Races in Orbit
Aug 20 '11 at 18:38
1
It is weird that "downgrading" is the only real option PHP gave us on some situations.
– Dan
Oct 8 '13 at 21:58
1
I tried to use wile stms->fetch() but it's skipping the first record. How can we loop over all result records?
– Lamar
Jun 5 '16 at 10:32
add a comment |
10
Please don't recommend "downgrading" from prepared statements to bogstandard strings. It's hard enough getting people to go the other way.
– Lightness Races in Orbit
Aug 20 '11 at 18:22
@Tomalak Geret'kal: right - thanks for the reminder, I've added a disclaimer. Not sure if I should remove the reference completely.
– vstm
Aug 20 '11 at 18:33
I'm not sure either.
– Lightness Races in Orbit
Aug 20 '11 at 18:38
1
It is weird that "downgrading" is the only real option PHP gave us on some situations.
– Dan
Oct 8 '13 at 21:58
1
I tried to use wile stms->fetch() but it's skipping the first record. How can we loop over all result records?
– Lamar
Jun 5 '16 at 10:32
10
10
Please don't recommend "downgrading" from prepared statements to bogstandard strings. It's hard enough getting people to go the other way.
– Lightness Races in Orbit
Aug 20 '11 at 18:22
Please don't recommend "downgrading" from prepared statements to bogstandard strings. It's hard enough getting people to go the other way.
– Lightness Races in Orbit
Aug 20 '11 at 18:22
@Tomalak Geret'kal: right - thanks for the reminder, I've added a disclaimer. Not sure if I should remove the reference completely.
– vstm
Aug 20 '11 at 18:33
@Tomalak Geret'kal: right - thanks for the reminder, I've added a disclaimer. Not sure if I should remove the reference completely.
– vstm
Aug 20 '11 at 18:33
I'm not sure either.
– Lightness Races in Orbit
Aug 20 '11 at 18:38
I'm not sure either.
– Lightness Races in Orbit
Aug 20 '11 at 18:38
1
1
It is weird that "downgrading" is the only real option PHP gave us on some situations.
– Dan
Oct 8 '13 at 21:58
It is weird that "downgrading" is the only real option PHP gave us on some situations.
– Dan
Oct 8 '13 at 21:58
1
1
I tried to use wile stms->fetch() but it's skipping the first record. How can we loop over all result records?
– Lamar
Jun 5 '16 at 10:32
I tried to use wile stms->fetch() but it's skipping the first record. How can we loop over all result records?
– Lamar
Jun 5 '16 at 10:32
add a comment |
As mentioned in php documentation mysqli_stmt::get_result, this method is supported since PHP 5.3.0.
And it is stated in the user notes section that:
This method requires the mysqlnd driver. Othervise you will get this error: Call to undefined method mysqli_stmt::get_result()
add a comment |
As mentioned in php documentation mysqli_stmt::get_result, this method is supported since PHP 5.3.0.
And it is stated in the user notes section that:
This method requires the mysqlnd driver. Othervise you will get this error: Call to undefined method mysqli_stmt::get_result()
add a comment |
As mentioned in php documentation mysqli_stmt::get_result, this method is supported since PHP 5.3.0.
And it is stated in the user notes section that:
This method requires the mysqlnd driver. Othervise you will get this error: Call to undefined method mysqli_stmt::get_result()
As mentioned in php documentation mysqli_stmt::get_result, this method is supported since PHP 5.3.0.
And it is stated in the user notes section that:
This method requires the mysqlnd driver. Othervise you will get this error: Call to undefined method mysqli_stmt::get_result()
answered Aug 27 '13 at 14:11
MohsenmeMohsenme
867818
867818
add a comment |
add a comment |
You're probably using old version of PHP not supporting get_result() as stated on manual page
(No version information available, might only be in SVN)
This is right. It usually means there's no release with this function in.
– Lightness Races in Orbit
Aug 20 '11 at 18:19
add a comment |
You're probably using old version of PHP not supporting get_result() as stated on manual page
(No version information available, might only be in SVN)
This is right. It usually means there's no release with this function in.
– Lightness Races in Orbit
Aug 20 '11 at 18:19
add a comment |
You're probably using old version of PHP not supporting get_result() as stated on manual page
(No version information available, might only be in SVN)
You're probably using old version of PHP not supporting get_result() as stated on manual page
(No version information available, might only be in SVN)
answered Aug 20 '11 at 17:59
genesisgenesis
43.5k1582111
43.5k1582111
This is right. It usually means there's no release with this function in.
– Lightness Races in Orbit
Aug 20 '11 at 18:19
add a comment |
This is right. It usually means there's no release with this function in.
– Lightness Races in Orbit
Aug 20 '11 at 18:19
This is right. It usually means there's no release with this function in.
– Lightness Races in Orbit
Aug 20 '11 at 18:19
This is right. It usually means there's no release with this function in.
– Lightness Races in Orbit
Aug 20 '11 at 18:19
add a comment |
The manual page doesn't give any clear information on which minimum version of PHP is needed for get_result() to work:
(No version information available, might only be in SVN)
I don't know the background to this, but it may simply not be available in your PHP version.
You could use fetch() instead.
Ok, I thinkt that might be the case. But can I ask how I can get rows in a result set using mysqli and prepared statements?
– einstein
Aug 20 '11 at 18:03
@Woho see my update
– Pekka 웃
Aug 20 '11 at 18:03
I don't like using fetch, because I have so much columns. Is there another way?
– einstein
Aug 20 '11 at 18:05
@Wohofetch_array()for example
– Pekka 웃
Aug 20 '11 at 18:07
add a comment |
The manual page doesn't give any clear information on which minimum version of PHP is needed for get_result() to work:
(No version information available, might only be in SVN)
I don't know the background to this, but it may simply not be available in your PHP version.
You could use fetch() instead.
Ok, I thinkt that might be the case. But can I ask how I can get rows in a result set using mysqli and prepared statements?
– einstein
Aug 20 '11 at 18:03
@Woho see my update
– Pekka 웃
Aug 20 '11 at 18:03
I don't like using fetch, because I have so much columns. Is there another way?
– einstein
Aug 20 '11 at 18:05
@Wohofetch_array()for example
– Pekka 웃
Aug 20 '11 at 18:07
add a comment |
The manual page doesn't give any clear information on which minimum version of PHP is needed for get_result() to work:
(No version information available, might only be in SVN)
I don't know the background to this, but it may simply not be available in your PHP version.
You could use fetch() instead.
The manual page doesn't give any clear information on which minimum version of PHP is needed for get_result() to work:
(No version information available, might only be in SVN)
I don't know the background to this, but it may simply not be available in your PHP version.
You could use fetch() instead.
answered Aug 20 '11 at 18:01
Pekka 웃Pekka 웃
357k1178421013
357k1178421013
Ok, I thinkt that might be the case. But can I ask how I can get rows in a result set using mysqli and prepared statements?
– einstein
Aug 20 '11 at 18:03
@Woho see my update
– Pekka 웃
Aug 20 '11 at 18:03
I don't like using fetch, because I have so much columns. Is there another way?
– einstein
Aug 20 '11 at 18:05
@Wohofetch_array()for example
– Pekka 웃
Aug 20 '11 at 18:07
add a comment |
Ok, I thinkt that might be the case. But can I ask how I can get rows in a result set using mysqli and prepared statements?
– einstein
Aug 20 '11 at 18:03
@Woho see my update
– Pekka 웃
Aug 20 '11 at 18:03
I don't like using fetch, because I have so much columns. Is there another way?
– einstein
Aug 20 '11 at 18:05
@Wohofetch_array()for example
– Pekka 웃
Aug 20 '11 at 18:07
Ok, I thinkt that might be the case. But can I ask how I can get rows in a result set using mysqli and prepared statements?
– einstein
Aug 20 '11 at 18:03
Ok, I thinkt that might be the case. But can I ask how I can get rows in a result set using mysqli and prepared statements?
– einstein
Aug 20 '11 at 18:03
@Woho see my update
– Pekka 웃
Aug 20 '11 at 18:03
@Woho see my update
– Pekka 웃
Aug 20 '11 at 18:03
I don't like using fetch, because I have so much columns. Is there another way?
– einstein
Aug 20 '11 at 18:05
I don't like using fetch, because I have so much columns. Is there another way?
– einstein
Aug 20 '11 at 18:05
@Woho
fetch_array() for example– Pekka 웃
Aug 20 '11 at 18:07
@Woho
fetch_array() for example– Pekka 웃
Aug 20 '11 at 18:07
add a comment |
I´m guessing it´s the line below that, change:
$info = $result->fecth_array(MYSQLI_ASSOC);
to:
$info = $result->fetch_array(MYSQLI_ASSOC);
ok changed that. But php issued an error before mysqli::fetch_array();
– einstein
Aug 20 '11 at 17:59
add a comment |
I´m guessing it´s the line below that, change:
$info = $result->fecth_array(MYSQLI_ASSOC);
to:
$info = $result->fetch_array(MYSQLI_ASSOC);
ok changed that. But php issued an error before mysqli::fetch_array();
– einstein
Aug 20 '11 at 17:59
add a comment |
I´m guessing it´s the line below that, change:
$info = $result->fecth_array(MYSQLI_ASSOC);
to:
$info = $result->fetch_array(MYSQLI_ASSOC);
I´m guessing it´s the line below that, change:
$info = $result->fecth_array(MYSQLI_ASSOC);
to:
$info = $result->fetch_array(MYSQLI_ASSOC);
answered Aug 20 '11 at 17:57
jeroenjeroen
82.3k1699123
82.3k1699123
ok changed that. But php issued an error before mysqli::fetch_array();
– einstein
Aug 20 '11 at 17:59
add a comment |
ok changed that. But php issued an error before mysqli::fetch_array();
– einstein
Aug 20 '11 at 17:59
ok changed that. But php issued an error before mysqli::fetch_array();
– einstein
Aug 20 '11 at 17:59
ok changed that. But php issued an error before mysqli::fetch_array();
– einstein
Aug 20 '11 at 17:59
add a comment |
check to see it your PHP mysql native driver is enable. get->result() only works when mysql native driver is enable. http://www.php.net/manual/en/mysqli-stmt.get-result.php
add a comment |
check to see it your PHP mysql native driver is enable. get->result() only works when mysql native driver is enable. http://www.php.net/manual/en/mysqli-stmt.get-result.php
add a comment |
check to see it your PHP mysql native driver is enable. get->result() only works when mysql native driver is enable. http://www.php.net/manual/en/mysqli-stmt.get-result.php
check to see it your PHP mysql native driver is enable. get->result() only works when mysql native driver is enable. http://www.php.net/manual/en/mysqli-stmt.get-result.php
answered Jul 6 '14 at 16:21
IfetayoIfetayo
3315
3315
add a comment |
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.
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%2f7133575%2fwhats-wrong-with-mysqliget-result%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