1

Ever since PHP went from 5+ to 7+ and changed all of the mysql_ tags, it made me wonder if I can create my own function name that I can use just in case PHP ever decides to change that function again. Then all I have to do it edit my own custom function instead of having to replace them all in every file.

Example, instead of using the old mysql_query(), I could name it my_query() and create a function like:

I know this is the old version, its not really relevant to my question

function my_query($sql)
{
    $result = mysql_query($sql);
    $sql_error = mysql_error();
    
        if ( DEBUG )
        {
            $display_sql = $sql;
        }

        if( !$result )
        {
            print("<center><font color=red><b>SQL Error!</b></font><br><br>Query:<br>$display_sql<br>$sql_error<br><br></center>");
        }

        return $result;
}

I can then make the changes inside of the my_query() and change use the mysqli_query($con, $res); inside of the one my_query() function instead of having to change all of the mysql_query()'s that I used a lot in all of my files.

My only question is if that would make the site run slower or not noticable, same loading speed using my own custom function name? Thanks

3
  • 1
    Executing the SQL query takes much more time than using the own function. (Nearly) all frame sets use such a wrapper around the sql query.
    – Wiimm
    Commented Jul 6 at 21:15
  • Why $display_sql = $sql;? You can use $sql directly in the error output.
    – Wiimm
    Commented Jul 6 at 21:16
  • 2
    The general question of overhead of PHP function calls is discussed here and in many other places. The short answer is yes, there is a slight overhead, but if your application is so sensitive to performance that function call overhead is a deal-breaker, then you probably shouldn't be using PHP in the first place. Commented Jul 6 at 21:43

0

Browse other questions tagged or ask your own question.