خطای اتصال به دیتابیس mysql_connect

  • نویسنده موضوع yoosef
  • تاریخ شروع

yoosef

کاربر عضو
سلام

خوبین

من یک کد دارم که چند سال پیش نوشته شده برای همین الان روی هاست و php 7 خطا میده که روش mysql_connect منقضی شده و از mysqli استفاده کنید

من هیچی بلد نیستم چیکار باید کنم ؟

این کدهامه

فایل config.php

<?php
session_start();
defined("DB_SERVER") ? null : define("DB_SERVR","localhost");
defined("DB_USER") ? null : define("DB_USER", "root");
defined("DB_PASS") ? null : define("DB_PASS", "");
defined("DB_NAME") ? null : define("DB_NAME","");
date_default_timezone_set('Asia/Tehran');
function is_admin()
{
return (isset($_SESSION['spuser']) && $_SESSION['spuser']=='spuser');

}
?>




اینم فایل database.php

<?php
require_once 'config.php';
class DB{
private $connection;

private $magic_quotes_active;

private $real_escape_string_exist;

function __construct(){
$this->connect();
$this->magic_quotes_active=get_magic_quotes_gpc();
$this->real_escape_string_exist=function_exists("mysql_real_escape_string");
}

public function connect(){
$this->connection=mysql_connect(DB_SERVR,DB_USER,DB_PASS);
if(!$this->connection){
die('Database Connection failed. <br>'.mysql_error());
}
else {
$db_select=mysql_select_db(DB_NAME,$this->connection);
if(!$db_select)
{
die('Datbase Selecttion Failed. <br>'.mysql_error());
}
else {
mysql_set_charset("utf8");
}
}
}

public function disconnect()
{
if(isset($this->connection))
{
mysql_close($this->connection);
unset($this->connection);
}
}

public function query($sql){
$result=mysql_query($sql,$this->connection);
$this->confirm_query($result);
return $result;
}

public function escape_value($value){
if($this->real_escape_string_exist)
{
if($this->magic_quotes_active){$value=stripslashes($value);}
$value=mysql_real_escape_string($value);
}else
{
if(!$this->magic_quotes_active){$value=addslashes($value);}
}
return $value;
}

public function fetch_array($result)
{
return mysql_fetch_array($result);
}

public function get_row($result)
{
return mysql_fetch_row($result);
}
public function result($result,$row,$field)
{
return mysql_result($result, $row, $field);
}
public function num_rows($result){
return mysql_num_rows($result);
}

public function insert_id($result){
//get the last inserted id over the current db connection.
return mysql_insert_id($this->connection);
}

public function affected_rows(){
return mysql_affected_rows($this->connection);
}

private function confirm_query($result){
if(!$result){
die("Database Query Failed. ".mysql_error());
}
}

}
$db= new DB();
?>


چجوری باید به روزشون کنم ؟

 

yoosef

کاربر عضو
آپ

اگر هزینه هم داشته باشه ایرادی نداره

 
آخرین ویرایش توسط مدیر:
بالا