我有2个php文件。 Joomla中包含的一些PHP代码直接包含在Sourcerer文章中。
这里似乎缺少一些东西。
我得到的第一个错误是:
<a>
警告显示在db-queries.php中的行,表示
Warning: mysqli_query() expects parameter 1 to be mysqli, null given
第二个错误是:
return $result = mysqli_query($db, $q);"
它向Joomla文章中的脚本显示了我想要检查num_rows的内容。这很清楚,因为没有结果。所以我主要需要修复错误#1 ...
所以不知何故,脚本并不知道$ db是。我被卡住了......任何人都可以提供帮助或给予一些小提示吗?
Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, null given.
$sqlhost = "xxx";
$sqluser = "xxx";
$sqlpassword = "xxx";
$sqldb = "xxx";
$db = mysqli_connect ($sqlhost, $sqluser, $sqlpasswort, $sqldb);
mysqli_set_charset($db,"utf8");
<?php include ("db-connect.php");
function squadresults ($squad_nr) {
global $db;
$q = "
SELECT spieler_id, spiel1, spiel2, spiel3, spiel4, spiel5, spiel6, netto, hdc, gesamt_hdc, qualifiziert
FROM onyc_ergebnisse
WHERE squad_nr='".$squad_nr."'
ORDER BY gesamt_hdc DESC, hdc ASC";
return $result = mysqli_query($db, $q);
}
答案 0 :(得分:0)
我建议:
<强> DB-connect.php 强>
$mysqli = new mysqli("localhost", "user", "pass", "db_test");
/* check the con */
if (mysqli_connect_errno()) {
printf("Error: %s\n", mysqli_connect_error());
exit();
}
/* set utf-8 */
if (!$mysqli->set_charset("utf8")) {
printf("Error on set utf8: %s\n", $mysqli->error);
exit();
}
db-queries上的
if ($result = mysqli_query($link, "SELECT Name FROM City LIMIT 10")) {
/* do my code */
printf("Numbers %d rows.\n", mysqli_num_rows($result));
}
/* If we have to retrieve large amount of data we use MYSQLI_USE_RESULT */
if ($result = $mysqli->query("SELECT * FROM City", MYSQLI_USE_RESULT)) {
/* Note, that we can't execute any functions which interact with the
server until result set was closed. All calls will return an
'out of sync' error */
if (!$mysqli->query("SET @a:='this will not work'")) {
printf("Error: %s\n", $mysqli->error);
}
$result->close();
}