如何修复错误参数必须是实现Countable的数组或对象

时间:2018-10-14 01:52:20

标签: php mysql unity3d

我知道此错误已得到解决,但是我正在遵循一个指南,使用MAMP创建我的第一个sql数据库,并且在打开数据库时收到此错误。有人可以帮我解决这个问题吗?我敢肯定这很简单,但是我完全按照指南进行操作,找不到任何错别字或错误。

错误是否可能与我设置数据库的方式有关,还是我在Unity中所做的事情?我假设615是指一行代码还是一个错误号?将来如何解决此问题或知道错误在哪里?

我遵循的指南是我在Sublime Text中创建脚本并将其保存在本地,然后使用MAMP访问它。我习惯于使用C ++和最近的C#进行编码,所以这些对我来说是象形文字。

Warning in .\libraries\sql.lib.php#615
 count(): Parameter must be an array or an object that implements Countable

Backtrace

.\libraries\sql.lib.php#2128: PMA_isRememberSortingOrder(array)
.\libraries\sql.lib.php#2079: PMA_executeQueryAndGetQueryResponse(
array,
boolean true,
string 'unityaccess',
string 'players',
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
string '',
string './themes/pmahomme/img/',
NULL,
NULL,
NULL,
string 'SELECT * FROM `players`',
NULL,
NULL,
)
.\sql.php#219: PMA_executeQueryAndSendQueryResponse(
array,
boolean true,
string 'unityaccess',
string 'players',
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
string '',
string './themes/pmahomme/img/',
NULL,
NULL,
NULL,
string 'SELECT * FROM `players`',
NULL,
NULL,
)

这是导致错误消息的代码。

<?php

$con = mysqli_connect('localhost', 'root', 'root', 'unityaccess');

//check that connection happened
if (mysqli_connect_errno())
{
    echo "1: Connection failed"; //error code #1 = connection failed
    exit();
}

$username = $_POST ["username"];
$password = $_POST["password"];

//check if name exists
$namecheckquery = "SELECT username FROM players WHERE username='" . $username . "'";

$namecheck = mysqli_query($con, $namecheckquery) or die("2: Name check query failed"); //error code #2 - name check query failed

if (mysqli_num_rows($namecheck) > 0)
{
    echo "3: Name already exists"; //error code #3 - name exists cannot register
    echo();
}

//add user to the table
$salt = "\$5\$rounds=5000\$" . "steamedhams" . $username . "\$";
$hash = crypt($password, $salt);
$insertuserquery = "INSERT INTO players (username, hash, salt) VALUES ('" . $username . "', '" . $hash . "', '" . $salt . "');";
mysqli_query($con, $insertuserquery) or die("4: Insert player query failed"); //error code #4 - insert query failed

echo ("0");



?>

2 个答案:

答案 0 :(得分:3)

  1. 转到此文件:.\libraries\sql.lib.php

  2. 在第615行上查找错误。您会发现count()未正确关闭,导致通过了boolean而不是array/object

  3. 用以下内容替换整行615:|| ((count($analyzed_sql_results['select_expr']) == 1)

应该可以。

答案 1 :(得分:3)

此答案适用于PHP 7.2.24(使用Ubuntu 18.04LTS),类似于Zeke的答案:

  1. 编辑:/usr/share/phpmyadmin/libraries/sql.lib.php
  2. 关闭支架在#613行上的错误位置
    || (count($analyzed_sql_results['select_expr'] == 1)
change to
    || (count($analyzed_sql_results['select_expr']) == 1
  1. 保存文件