dongshuzhuo5659 2018-07-04 05:35
浏览 35

与Php / mysqli的麻烦 - 不再工作

desperately need some help here. I've recently gone back to a game I had developed a few years ago now that I've got some free time. When I left it all the Php/mysqli code was working perfectly fine. No issues at all.

However, now it is not. For example, when I try to login to the game it I'm getting username and/or password is invalid. Now, obviously I'm using a known username/password.

I've found that it works fine on php5.1 but not on any higher version. I figured I'd have to rewrite the code to suit php7 but I'm having problems with that.

I've tested my code on various online checkers with various php7 versions and I get this error every time... Fatal error: Uncaught Error: Class 'mysqli' not found in ... but no syntax errors, no deprecated code.

I have confirmed with my host that mysqli is installed (cpanel) so clearly that's not the issue.

I've also checked using this code snippet ...

if (!function_exists('mysqli_init') && !extension_loaded('mysqli')) {
 echo 'you dont have';
 } else {
 echo 'you have!';
 }

I have!

I've also run checks that there is a database connection. And when I check the php error log in cpanel I'm not getting any errors at all.

So what's going on? It's as if the data isn't being retrieved from the database. I used to be able to test by changing all the POST syntax to GET so I could manually login via the url but that doesn't work either now.

Any help is much appreciated and thanks in advance.

My login script:

<?php 

$dbhost = 'localhost';
$dbuser = 'me';
$dbpass = 'xxxx';
$dbname = 'me_again';

$nameTable = 'table';
$string = '';


$conn = new mysqli($dbhost,$dbuser,$dbpass,$dbname);

if($conn->connect_error) {
    $string = 'valid=8';

} else {

$username = '';
$userpass = '';
$loginRequest = '';


  if (isset($_POST['username'])) {
    $username = $_POST['username'];
  }
   if (isset($_POST['userpass'])) {
    $userpass = $_POST['userpass'];
  }
   if (isset($_POST['loginRequest'])) {
    $loginRequest = $_POST['loginRequest'];
  } 


 if($loginRequest == "login") {

      if ($s = mysqli_prepare($conn, "SELECT `usersalt` FROM `{$nameTable}` WHERE `username`=? LIMIT 1")) {
         mysqli_stmt_bind_param($s, "s", $username);
         mysqli_stmt_execute($s);
         mysqli_stmt_store_result($s);
         if (1 == mysqli_stmt_num_rows($s)) {
            mysqli_stmt_bind_result($s, $usersalt);
            // fetch only 1 result
            mysqli_stmt_fetch($s);

       if ($s2 = mysqli_prepare($conn, "SELECT `username`,`cat1`,`cat2`,`cat3`,`cat4`,`cat5`,`cat6`,`userscore`,`userplayed`,`correct` FROM `{$nameTable}` WHERE `username`=? AND `userpass`=? ")) {
               $hashedpass = sha1($usersalt . $userpass);
               mysqli_stmt_bind_param($s2, "ss", $username, $hashedpass);
               mysqli_stmt_execute($s2);
               mysqli_stmt_store_result($s2);
               if (1 == mysqli_stmt_num_rows($s2)) {
                  mysqli_stmt_bind_result($s2, $res_name, $res_cat1, $res_cat2, $res_cat3, $res_cat4, $res_cat5, $res_cat6, $res_score, $res_played, $res_correct );
                  // fetch only 1 result
                  mysqli_stmt_fetch($s2);
                  header('Content-Type: text/xml');
                  echo "<?xml version='1.0'?>";
                  echo "<".$nameTable.">";
                  echo "<player>";
                  echo "<username>".$res_name."</username>";
                  echo "<cat1>".(int)$res_cat1."</cat1>"; 
                  echo "<cat2>".(int)$res_cat2."</cat2>"; 
                  echo "<cat3>".(int)$res_cat3."</cat3>";
                  echo "<cat4>".(int)$res_cat4."</cat4>"; 
                  echo "<cat5>".(int)$res_cat5."</cat5>"; 
                  echo "<cat6>".(int)$res_cat6."</cat6>";                   
                  echo "<userscore>".(int)$res_score."</userscore>";
                  echo "<userplayed>".(int)$res_played."</userplayed>"; 
                  echo "<correct>".(int)$res_correct."</correct>";                           
               }
               mysqli_stmt_close($s2);

} else {
               $msg = ((is_object($conn)) ? mysqli_error($conn) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false));
               $string = 'valid=0';
            }
         } else {
            $msg = ((is_object($conn)) ? mysqli_error($conn) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false));
            $string = 'valid=1';

         }
         mysqli_stmt_close($s);
      } else {
         $msg = ((is_object($conn)) ? mysqli_error($conn) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false));
         $string = 'valid=2';
      }

}
}

$conn->close();

echo $string;

?>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 delta降尺度计算的一些细节,有偿
    • ¥15 Arduino红外遥控代码有问题
    • ¥15 数值计算离散正交多项式
    • ¥30 数值计算均差系数编程
    • ¥15 redis-full-check比较 两个集群的数据出错
    • ¥15 Matlab编程问题
    • ¥15 训练的多模态特征融合模型准确度很低怎么办
    • ¥15 kylin启动报错log4j类冲突
    • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
    • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序