Code (27-42):

function xtc_db_connect($server = DB_SERVER, $username = DB_SERVER_USERNAME, $password = DB_SERVER_PASSWORD, $database = DB_DATABASE, $link = 'db_link') { 
    global $$link; 

if (USE_PCONNECT == 'true') { 
     $$link = mysql_pconnect($server, $username, $password); 
    mysql_query("SET SESSION sql_mode=''"); 
} else { 
    $$link = mysql_connect($server, $username, $password); 
    mysql_query("SET SESSION sql_mode=''"); 

   } 

if ($$link) mysql_select_db($database); 

return $$link; 
  }  

This code works with php 5.4, but after update to php 5.5 i have this mistake:

Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /homepages/33/d183561635/htdocs/xtc.../inc/xtc_db_connect.inc.php on line 34

I understand that mysql is deprecated, but please help, i don´t know what i must exactly do.

How must be the correct code to work with php 5.5?

    If all you get is the "Deprecated" notice, it will still work, but it may not in a future update. As an immediate band-aid, you can make sure that display_errors is turned off, but the real fix is to either use theMySQLi extension, or the PDO extension (which I personally prefer).

      Thanks for answer, but can you help how to fix the code.

      How must be the correct code to work use the MYSQLi or the PDO Extension

      The deprecated error is in this line:
      mysql_query("SET SESSION sql_mode=''");

      Can you help me?

        The SQL statement is the same either way, so it is just a matter of running a simple query with either of the suggested extensions. The syntax and function name is actually almost the same for MySQLi if you use the "procedural version": mysqli_query, though personally I prefer PDO (but that's because I use PostgreSQL more than MySQL): PDO query.

        Incidentally, what that statement is doing is setting the server SQL mode to the default, and seeing that it is the default, it might not even be necessary, if the MySQL installation was not configured to set it otherwise.

          Perhaps the biggest difference between mysql and mysqli is that with the newer one (The i in mysqli stands for improved) requires you to supply the database resource when you try to run a query. The old mysql code, if you don't supply a database resource object, will simply assume that you want to use whatever mysql connection was last connected. In your case, the var $link is this database resource. Interestingly, $link is declared as a global variable but it is also returned by the function. This seems weird to me. It should either be global or returned by the function, but not both.

          The other guys' posts are basically pointing you in the right direction. You should be able to replace each and every mysql function with some mysqli counterpart -- you'll just need to make sure that you supply the $link that should be used when you do a query, etc.

            Write a Reply...