gpt4 book ai didi

php - fatal error : Call to a member function set_charset()

转载 作者:搜寻专家 更新时间:2023-10-30 20:18:19 27 4
gpt4 key购买 nike

我正在使用 Cpanel 开发我的应用程序。它给出了错误

Fatal error: Call to a member function set_charset() on a non-object in /home/restaur  /public_html/restaurant/includes/connect_database.php on line 3

当我访问“www.yyyyy.com/filename/”时

这是我的连接数据库脚本

<?php 
include($_SERVER['DOCUMENT_ROOT'].'/YOUR_FOLDER/variables/variables.php');
$connect->set_charset('utf8');
?>

我的关闭数据库脚本

<?php
include($_SERVER['DOCUMENT_ROOT'].'/YOUR_FOLDER/variables/variables.php');
$connect->close();
?>

我的变量脚本

<?php
// database configuration
$host ="db_host_name";
$user ="db_username";
$pass ="db_pasword";
$database = "database_name";
$connect = new mysqli($host, $user, $pass,$database) or die("Error : ".mysql_error());?>

最佳答案

应该是这样的

$host ="db_host_name";
$user ="db_username";
$pass ="db_pasword";
$database = "database_name";

// variables.php
$connect = new mysqli($host, $user, $pass, $database);

/* check connection */
if ($connect->connect_errno) {
printf("Connect failed: %s\n", $connect->connect_error);
exit();
}

现在在 connect_database.php

// Make sure your included path is correct
include($_SERVER['DOCUMENT_ROOT'].'/YOUR_FOLDER/variables/variables.php');
global $connect;

$connect->set_charset('utf8');

这将帮助您更深入地了解global

关于php - fatal error : Call to a member function set_charset(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22574369/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com