Regarding the problem of custom methods in mysqli, please solve it?
别闹i
别闹i 2017-09-18 15:05:55
0
1
1701

QQ图片20170918145956.png

When using $mysqli in a custom function, an error is reported. The red line at the bottom of $mysqli indicates QQ图片20170918150003.png

Although $mysqli reports a syntax error, it is marked with a red line. , but the data is still queried, but the loading is super slow, taking dozens of seconds, which is obviously abnormalTZUMIA06_EE@A(DUY]()0OW.png

This is the database configuration

别闹i
别闹i

reply all(1)
Ty80

It is recommended to place require 'mysqli_connect.php'; outside the custom function, at the top of the program. Using the $mysqli variable in a function requires a global declaration. Write global $mysqli;

at the top of the function body.
  • reply Warning: mysqli::query(): Couldn't fetch mysqli in D:phpStudyWWWmysqli_objmysqli_insert.php on line 52 //Thank you, I adopted your method, no syntax error was reported, and the above error was reported when loading
    别闹i author 2017-09-18 16:32:46
  • reply global $mysqli;---unset($mysqli);//After defining the global variable, I destroyed it at the end of the method. Is this necessary?
    别闹i author 2017-09-19 14:41:08
  • reply Just delete the line $mysqli->close(); and it will be fine.
    PHP中文网 author 2017-09-19 09:01:03
  • reply The db connection has been closed after this first visit, so new connections cannot be generated.
    PHP中文网 author 2017-09-19 09:01:39
  • reply You should destroy it when the page ends and should not be placed in a function, otherwise the database will be closed the second time you call the function.
    PHP中文网 author 2017-09-23 10:51:29
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template