Asked  8 Months ago    Answers:  5   Viewed   41 times

Thanks to the answers I have figured out that I am unable to use fetch_all() because i am using PHP 5.2.17 - fetch_assoc with while loop worked.


The function I am using fetch_all is coming back with this error:

Fatal error: Call to undefined method mysqli_result::fetch_all() in

$mysqli = new mysqli($host, $username, $password, $database);
$query = "LONG QUERY that works, tested in phpmyadmin"
$result = $mysqli->query($query);
$result->fetch_all(); or  $mysqli->fetch_all() tried both
mysqli_fetch_all() was already tried.
$mysqli->close(); 

I am able to connect to the DB and I have pulled single rows. When I place the query in PHPMYADMIN I get 5 rows back.

Does this function even work? Is there a way I can place my data into an assoc array on my own?

 Answers

26

This function is available since PHP 5.3.0. Possibly your version is older. Use fetch_assoc() instead.

while ($row = $result->fetch_assoc()) {
    // do what you need.
}
Wednesday, March 31, 2021
 
employeegts
answered 8 Months ago
73

The problem is with PHP variable scoping. Add this line inside of allServers() function before you refer to the $link variable for the first time:

global $link;

See more here: http://php.net/manual/en/language.variables.scope.php

Wednesday, March 31, 2021
 
SheppardDigital
answered 8 Months ago
39

yo need create the user "pma" in mysql or change this lines(user and password for mysql):

/* User for advanced features */
$cfg['Servers'][$i]['controluser'] = 'pma'; 
$cfg['Servers'][$i]['controlpass'] = '';

Linux: /etc/phpmyadmin/config.inc.php

Tuesday, July 13, 2021
 
ShadowZzz
answered 4 Months ago
27

[EDIT] See @bobince's post below for a more correct and thorough answer. This answer has been retained for reference and edited to be less wrong.

A valid name in JavaScript must start with a Unicode letter (p{L}), dollar sign, or underscore then can contain any of those characters as well as numbers, combining diacritical (accent) characters, and various joiner punctuation and zero-width spaces. Additionally, it cannot be a word reserved by the JavaScript language (e.g. abstract, as, boolean, break, byte, case, etc).

A full regular expression solution would be quite complicated in plain JavaScript but the XRegExp Unicode plugin could greatly simplify the task. This online function name tester might also be useful.

[ORIGINAL] Here is an incomplete regular expression, using only the US ASCII letters:

var fnNameRegex = /^[$A-Z_][0-9A-Z_$]*$/i;

You also must check that it doesn't match any reserved words (e.g. abstract, boolean, break, byte, ..., while, with, etc). Here's a start for that list, and an example function:

var isValidFunctionName = function() {
  var validName = /^[$A-Z_][0-9A-Z_$]*$/i;
  var reserved = {
    'abstract':true,
    'boolean':true,
    // ...
    'with':true
  };
  return function(s) {
    // Ensure a valid name and not reserved.
    return validName.test(s) && !reserved[s];
  };
}();
Sunday, August 1, 2021
 
Zword
answered 3 Months ago
36

This is how your code should look (with added SQL Injection protection):

<?php
include "dbinfo.php"; //contains mysqli_connect information (the $mysqli variable)
//inputs
$name = mysqli_real_escape_string($_GET['name']);
$text = mysqli_real_escape_string($_GET['text']);

$sqlqr = "INSERT INTO `ncool`.`coolbits_table` (`name`, `text`, `date`) VALUES ('" . $name . "', '" . $text . "', CURRENT_TIMESTAMP);";

mysqli_query($mysqli,$sqlqr); //function where the magic happens.
?>

Take a look at what I've done. Firstly I've escaped the user input you're retrieving into the $name and $text variables (this is pretty much a must for security reasons) and as others have suggested you should preferably be using prepared statements.

The problem is that you weren't surrounding string values with single quotes ('), which is a requirement of the SQL syntax.

I hope this helps to answer your question.

Thursday, September 2, 2021
 
Pachvarsh
answered 2 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :
 
Share