Function eregi() is deprecated

Donator
Înscris
25 Ian 2009
Mesaje
441
Am o problema cu un script php, imi da aceste erori:

Deprecated: Function eregi() is deprecated in /system/library/classes/dbclass.php on line 36

Deprecated: Function eregi() is deprecated in /system/library/classes/paging.cls.php on line 10

Deprecated: Function eregi() is deprecated in /system/library/classes/paging.cls.php on line 31

Deprecated: Function eregi() is deprecated in /system/library/classes/dbclass.php on line 36


dbclass.php

<?
//_________define class_________________________//
class dbclass {
var $CONN;
function dbclass() { //constructor
$conn = mysql_connect(DB_SERVER,DB_USERNAME,DB_PASSWORD);
if(!$conn)
{ $this->error("Connection attempt failed"); }
if(!mysql_select_db(DB_DATABASE,$conn))
{ $this->error("Database Selection failed"); }
$this->CONN = $conn;
return true;
}
//_____________close connection____________//
function close(){
$conn = $this->CONN ;
$close = mysql_close($conn);
if(!$close){
$this->error("Close Connection Failed"); }
return true;
}
//______________catch error__________________//
function error($text) {
$no = mysql_errno();
$msg = mysql_error();
echo "<hr><font face=verdana size=2>";
echo "<b>Custom Message :</b> $text<br><br>";
echo "<b>Error Number :</b> $no<br><br>";
echo "<b>Error Message :</b> $msg<br><br>";
echo "<hr></font>";
exit;
}
//_____________select records___________________//
function select ($sql=""){
if(empty($sql)) { return false; }
if(!eregi("^select",$sql)){
echo "Wrong Query<hr>$sql<p>";
return false; }
if(empty($this->CONN)) { return false; }
$conn = $this->CONN;
$results = @mysql_query($sql,$conn);
if((!$results) or empty($results)) { return false; }
$count = 0;
$data = array();
while ( $row = mysql_fetch_array($results)) {
$data[$count] = $row;
$count++; }
mysql_free_result($results);
return $data;
}
//__________total rows affected______________________//
function affected($sql="") {
if(empty($sql)) { return false; }
if(!eregi("^select",$sql)){
echo "Wrong Query<hr>$sql<p>";
return false; }
if(empty($this->CONN)) { return false; }

$conn = $this->CONN;
$results = @mysql_query($sql,$conn);
if( (!$results) or (empty($results)) )
{ return false; }
$tot=0;
$tot=mysql_affected_rows();
return $tot;
}
//________insert record__________________//
function insert ($sql=""){
if(empty($sql)) { return false; }
if(!eregi("^insert",$sql)){ return false; }
if(empty($this->CONN)){ return false; }
$conn = $this->CONN;
$results = @mysql_query($sql,$conn);
if(!$results){
$this->error("Insert Operation Failed..<hr>$sql<hr>");
return false; }
$id = mysql_insert_id();
return $id;
}
//___________edit and modify record___________________//
function edit($sql="") {
if(empty($sql)) { return false; }
if(!eregi("^update",$sql)){ return false; }
if(empty($this->CONN)){ return false; }
$conn = $this->CONN;
$results = @mysql_query($sql,$conn);
$rows = 0;
$rows = @mysql_affected_rows();
return $rows;
}
//____________generalize for all queries___________//
function sql_query($sql="") {

if(empty($sql)) { return false; }
if(empty($this->CONN)) { return false; }
$conn = $this->CONN;
$results = mysql_query($sql,$conn) or $this->error("Something wrong in query<hr>$sql<hr>");

if(!$results){
$this->error("Query went bad ! <hr>$sql<hr>");
return false; }
if(!eregi("^select",$sql)){return true; }
else {
$count = 0;
$data = array();
while ( $row = mysql_fetch_array($results))
{ $data[$count] = $row;
$count++; }
mysql_free_result($results);
return $data;
}
}

function adder($sql="") {
if(empty($sql))
{ return false; }
if(empty($this->CONN))
{ return false; }

$conn = $this->CONN;
$results = @mysql_query($sql,$conn);

if(!$results)
$id = "";
else
$id = mysql_insert_id();
return $id;
}

/**
* @return array
* @param string $tablename the tablename
* @desc check if a table with the given name exists in DB
*/
function table_exists($tablename)
{
$conn = $this->CONN ;

if(empty($conn)) { return false; }

$results = mysql_list_tables(DB_DATABASE) or die("Could not access Table List...<hr>" . mysql_error());

if(!$results){

$message = "Query went bad!";
//mysql_close($conn);
die($message);
return false;

}else{

$count = 0;
$data = array();
while ( $row = mysql_fetch_array($results)) {
if ($row[0]==$tablename) {
return true;
// mysql_close($conn);
exit;
}
}
mysql_free_result($results);
//mysql_close($conn);
return false;
}
}



function extraqueries($sql="") {

if(empty($sql)) { return false; }
if(empty($this->CONN)) { return false; }
$conn = $this->CONN;
$results = mysql_query($sql,$conn) or $this->error("Something wrong in query<hr>$sql<hr>");

if(!$results){
$this->error("Query went bad ! <hr>$sql<hr>");
return false; }
else {
$count = 0;
$data = array();
while ( $row = mysql_fetch_array($results))
{ $data[$count] = $row;
$count++; }
mysql_free_result($results);
return $data;
}
}

function db_query($sql="") {
if(empty($sql)) { return false; }
if(empty($this->CONN)) { return false; }
$conn = $this->CONN;
$results = mysql_query($sql,$conn) or $this->error("Something went wrong in the query<hr>$sql<hr>");
if(!$results){
$this->error("Query went bad ! <hr>$sql<hr>");
return false; }
else
return $results;
}

function db_fetch_row($result) {
return mysql_fetch_row($result);
}

function db_free_result($result) {
@mysql_free_result($result);
}

function db_num_rows($result) {
return mysql_num_rows($result);
}

function db_num_fields($result) {
return mysql_num_fields($result);
}

function db_field_name($result) {
return mysql_field_name($result);
}

function db_field_type($result) {
return mysql_field_type($result);
}

} //________ends the class here__________//


?>



paging.cls.php


<?
/*
paging_inc.php made on : 26 June, 2003
To be included in the listing scripts to get dynamic paging. "$page_limit" will be given
in the SQL query and the out put will be given in "$page_link"
*/
$PHP_SELF = $_SERVER['PHP_SELF'];
$page = $_REQUEST['page'];
$set = $_REQUEST['set'];
if(eregi("paging_inc.php",$PHP_SELF)) {
print "<h4>Ooops! Please include this file as a part of a listing script</h4>";
exit;
}
//total records
$tot_rec_size = $tot;

if(!isset($tot_rec_size)||empty($tot_rec_size)) $tot_rec_size = 0;

//initialize variables
$max_noof_sets = 0;
$cur_page_recs = 0;
$page_link = "";
$page_limit = "";
if(!isset($var_extra) || empty($var_extra))
$var_extra = "";
$start_limit = 0;
//set paging paramters

if(!isset($set)||$set==0||empty($set)) $set=1;
if(!isset($page)||$page==0||empty($page)) $page=1;
if (eregi("admin", $PHP_SELF)){
$reclimit = $RECORD_LIMIT;

}else
$reclimit = REC_RECLIMIT;

$max_noof_sets = ceil(($tot_rec_size / $reclimit )/REC_PAGELIMIT);
$cur_page_recs = ($tot_rec_size - ((REC_PAGELIMIT*$reclimit)*($set-1)));
$max_noof_pages = ceil($tot_rec_size / $reclimit);

if(($set*REC_PAGELIMIT)==$page){
$next_set = $set+1;
}else{
$next_set = $set;
}
if($page == (($set-1)*REC_PAGELIMIT)+1){
$prev_set = $set-1;
}else{
$prev_set = $set;
}

$start_page = 1;
$prev_pageno = (($set - 1) * REC_PAGELIMIT);
$prev_pageno=$page-1;

if($prev_pageno==0){
$page_link .= "<font class=\"mainlinks\">Prev &nbsp;&nbsp;&nbsp;</font>";
}else{
$page_link .= "<a href=\"$PHP_SELF?set=$prev_set&page=$prev_pageno$var_extra&sorton=$_REQUEST[sorton]\"><font class=\"mainlinks\">
Prev</a></font>&nbsp;&nbsp; ";
}
$start_page = ((($set - 1) * REC_PAGELIMIT)+1);
for($i=1;$i<=REC_PAGELIMIT;$i++){
if($start_page==$page)
$page_link .= "<a href=\"$PHP_SELF?set=$set&page=$start_page$var_extra&sorton=$_REQUEST[sorton]\" class=\"mainlinks\">[".$start_page."]</a>&nbsp;&nbsp;&nbsp; ";
else
$page_link .= "<a href=\"$PHP_SELF?set=$set&page=$start_page$var_extra&sorton=$_REQUEST[sorton]\" class=\"mainlinks\">
".$start_page."</a>&nbsp;&nbsp;&nbsp; ";

if(($i*$reclimit)>=$cur_page_recs) break;
$start_page++;
}
$cnt = 1;
for ($x=1;$x<=$max_noof_pages;$x=$x + REC_PAGELIMIT){
$st = $x;
$end = $cnt*REC_PAGELIMIT;
$set = ceil($end / REC_PAGELIMIT);
if (($cnt % REC_PAGELIMIT) == 0) $br = "<br>"; else $br="";
$qpage_link .= "<a href=\"$PHP_SELF?set=$set&page=$st$var_extra&sorton=$_REQUEST[sorton]\" class=\"mainlinks\">[".$st . "-" . $end ."]</a>&nbsp;&nbsp;&nbsp; " . $br;
$cnt++;
}

$next_pageno=$page+1;

if($next_pageno==$max_noof_pages+1){
$page_link .= "<font class=\"mainlinks\">&nbsp;Next</font>";
}else{
$page_link .= "&nbsp;<a href=\"$PHP_SELF?set=$next_set&page=$next_pageno$var_extra&sorton=$_REQUEST[sorton]\"><font class=\"mainlinks\">Next</a></font>";
}

$upper_page_link=$qpage_link . "<hr>".$page_link;
$page_link .= "<hr>" . $qpage_link;
//the output variables
$start_limit = (($page-1)* $reclimit);
$page_limit = " LIMIT $start_limit,". $reclimit; //this var should be used in the SQL
?>


Am citit undeva ca se inlocuieste eregi cu preg_match, dar simpla inlocuierese pare ca nu e suficienta, trebuie modificare de cod.
 
Membru
Înscris
31 Oct 2014
Mesaje
15
Pai asta si trebuie sa faci, trebuie sa inlocuesti functia eregi cu o functie similara si sa modifici codul pentru a putea functiona corect.
In legatura cu preg_match, problema are o rezolvare simpla:

Trebuie sa mai adaugi un i :))

de ex: preg_match('/php/i', 'PHP');

Solutia este simpla, deoarece cele doua cuvinte pot avea variatii, unul cu litere mari, altul fara litere mari, aceasta functie nu va functiona, insa pentru a functiona, trebuie doar sa incluzi ceea ce ti-am aratat eu, exact cum ti-am aratat eu: "/text/i"

Sper ca te-am ajutat.


i - Case-insensitive matching.
 
Donator
Înscris
25 Ian 2009
Mesaje
441
logwords a spus:
Pai asta si trebuie sa faci, trebuie sa inlocuesti functia eregi cu o functie similara si sa modifici codul pentru a putea functiona corect.
In legatura cu preg_match, problema are o rezolvare simpla:

Trebuie sa mai adaugi un i :))

de ex: preg_match('/php/i', 'PHP');

Solutia este simpla, deoarece cele doua cuvinte pot avea variatii, unul cu litere mari, altul fara litere mari, aceasta functie nu va functiona, insa pentru a functiona, trebuie doar sa incluzi ceea ce ti-am aratat eu, exact cum ti-am aratat eu: "/text/i"

Sper ca te-am ajutat.


i - Case-insensitive matching.


Multumesc mult ! :)
 
Sus