简体   繁体   English

PHP7的MySQLi警告

[英]MySQLi warning with php7

I'm getting the following errors from php7 on a new Ubuntu server: 我在新的Ubuntu服务器上从php7收到以下错误:


Notice : Trying to get property of non-object in ~/tLogServ.php on line 14 注意 :尝试在第14行的〜/ tLogServ.php中获取非对象的属性

Warning : mysqli::query(): Couldn't fetch mysqli in ~/tLogServ.php on line 17 警告 :mysqli :: query():无法在第17行的〜/ tLogServ.php中获取mysqli

Fatal error : Uncaught Error: Call to a member function fetch_assoc() on null in ~/tLogServ.php:18 Stack trace: 致命错误 :未被捕获的错误:〜/ tLogServ.php:18中的成员函数fetch_assoc()调用为null堆栈跟踪:

0 {main}thrown in ~/tLogServ.php on line 18 0 {main}在第18行的〜/ tLogServ.php中抛出

Here's the tLogServ.php 这是tLogServ.php

    <?php
    header("Access-Control-Allow-Origin: *");
    header("Content-Type: application/json; charset=UTF-8");
    $request = json_decode( file_get_contents('php://input') );
    $variable = $request->data;
     // echo($variable);
     $result = $conn->query("SELECT password FROM login where userID LIKE          'technician'");
   $rows = $result->fetch_assoc();
   $passHashed = $rows['password'];

   if(password_verify($variable, $passHashed)){
    $loginMess = "success";
   }else{
    $loginMess = "fail";
   }

   echo json_encode($loginMess);

   $conn->close();
  ?>

and my connection script 和我的连接脚本

<?php
DEFINE ('user', '$%^*(');
DEFINE ('pass', '^*&%*');
DEFINE ('host', '1*&^*&^');
DEFINE ('DB', '^*%*(&%^');
$conn = new mysqli(host, user, pass, DB) OR die('Fail Whale ' . mysqli_connect_error());

?>

The notice will go away with input, but I'm unsure about and the warning and the fatal error it causes. 通知将随输入消失,但是我不确定警告及其引起的致命错误。

This code works without issue on Ubuntu 14 with PHP5. 这段代码在带有PHP5的Ubuntu 14上可以正常使用。 I've uncommented extension=php_mysqli.dll in php.ini. 我在php.ini中没有注释extension = php_mysqli.dll。 This is obviously a compatibility issue, but I'm unsure if I need to re-write my code or if it's a matter of a simple setting that I can't find. 显然这是一个兼容性问题,但是我不确定是否需要重新编写代码,或者这是我找不到的简单设置的问题。

The issue was two stupid mistakes. 问题是两个愚蠢的错误。

1)The user I referenced in my connection was not given proper rights. 1)我在连接中引用的用户未获得适当的权限。

and

2) 'Host' was defined as the IP of the localhost. 2)“主机”被定义为本地主机的IP。 For whatever reason this worked on Cat connection, but not on WiFI (both had static Ip's). 无论出于何种原因,这都适用于Cat连接,但不适用于WiFI(均具有静态Ip)。

For others with the same/similar issue. 对于其他具有相同/相似问题的用户。 Verify that your php.ini mysqli extension is enabled/uncommmented. 验证您的php.ini mysqli扩展已启用/未注释。 As AL was onto the issue was with mySQL settings not PHP/Ubuntu. 由于AL面临的问题是mySQL设置而不是PHP / Ubuntu。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM