PHP函数返回错误的值

时间:2016-10-02 09:11:41

标签: php sql function

我有这个功能

function getNick($uid)
{
    $sqli = "SELECT nick FROM users WHERE userid='".$uid."'";
    mysqli_real_escape_string($con,$sqli);
    $resulti = mysqli_query($con,$sqli);
    $rowi = mysqli_fetch_assoc($resulti);   
    if($resulti->num_rows > 0) return $rowi["nick"];
    else return "(none)";
}

基本上它应该根据用户的ID返回我的缺口。问题是我只能继续'(无)'。有趣的是我打印了实际的$ sqli并将其复制到phpMyAdmin中,它按预期工作。我甚至试图在没有IF的情况下打印缺口但我最终得到了空字符串。可能是什么问题?我忽略了什么吗?感谢

1 个答案:

答案 0 :(得分:1)

@echo off
setlocal EnableDelayedExpansion

set "fTmpPy=%TEMP%\~fTmp.py"

call :getLine "::python_beg" "::python_end" > "!fTmpPy!"

python "!fTmpPy!"

pause
exit /b 0

:getLine <beg str> <end str>
  set "bBegEnd=0"
  for /f "usebackq delims=" %%l in ("%~f0") do (
    if !bBegEnd! equ 1 (
      if "%%l" equ "%~2" ( exit /b 0 )
      setlocal DisableDelayedExpansion
      echo %%l
      endlocal
    ) else (
      if "%%l" equ "%~1" ( set "bBegEnd=1" )
    )
  )
exit /b 0

endlocal

::mark is unique - one character or string
::begin mark must be
::end mark is optional if it is on eof

::python_beg
print( 'Hello, world!' )
::python_end

有效

变量范围问题

使用上述方法在方法或

中传递连接

使用<?php $con = mysqli_connect("localhost","root","","test"); function getNick($uid,$con) { $sqli = "SELECT nick FROM users WHERE userid='".$uid."'"; mysqli_real_escape_string($con,$sqli); $resulti = mysqli_query($con,$sqli); $rowi = mysqli_fetch_assoc($resulti); if($resulti->num_rows > 0) return $rowi["nick"]; else return "(none)"; } echo getNick(1,$con); ?> 访问方法$GLOBALS['con']

中的连接