$i, 'server'=>$server, 'user'=>$user, 'password'=>$password); return $i; } // Both these functions call the one above. I could have named the function above mysql_connect but then the call to // it here would have been flagged up as PHP7 incompatible. function mysql_connect ($server=null, $user=null, $password=null) {return php7c_mysql_connect ($server, $user, $password);} function mysql_pconnect ($server=null, $user=null, $password=null) {return php7c_mysql_connect ($server, $user, $password);} // We have saved the username password from the mysql_connect call. Now lookup those things based on the // link identifier passed in, and create the actual database link. function mysql_select_db ($database_name, $link=null) { if (! ($label = php7c_mysql_get_link ($link, 'label'))) return false; //the label for this link global $PHP7CVARS; //save the link to the database along with the connection details $parts = explode (':', $PHP7CVARS[$label]['server']); $host = $parts[0]; $port = count($parts)>1 ? $parts[1] : null; $PHP7CVARS[$label]['link'] = mysqli_connect ($host, $PHP7CVARS[$label]['user'], $PHP7CVARS[$label]['password'], $database_name, $port); if (!isset ($PHP7CVARS['mysql']['link'])) $PHP7CVARS['mysql']['link'] = $PHP7CVARS[$label]['link']; return true; } // mysql_query will now return a mysqli_result object rather than a mysql resource. This // is then passed to the mysql_fetch and related functions below. This does not include all // mysql_ type functions, just the common ones I've come across. function mysql_close ($link=null) {return mysqli_close (php7c_mysql_get_link ($link));} function mysql_error ($link=null) {return mysqli_error (php7c_mysql_get_link ($link));} function mysql_errno ($link=null) {return mysqli_errno (php7c_mysql_get_link ($link));} // This function could be called before the connection has even been established, but mysqli_real_escape_string // requires a mysql link, so in this case I will check if it's already escaped and if not, escape it myself. function mysql_escape_string ($unescaped_string, $link=null) { if ($pl = php7c_mysql_get_link($link)) return mysqli_real_escape_string ($pl, $unescaped_string); //if the string does not (start with a slash or contain \\' or have a slash by itself) then strip extra slashes if (!preg_match ("/^'|\\\\\\\\'|[^\\\\]'/", $unescaped_string)) $unescaped_string = stripSlashes ($unescaped_string); //strip extra slashes return addSlashes ($unescaped_string); //escape or add slashes } function mysql_insert_id ($link=null) {return mysqli_insert_id (php7c_mysql_get_link ($link));} function mysql_real_escape_string ($unescaped_string, $link=null) {return mysql_escape_string ($unescaped_string, $link);} function mysql_query ($query, $link=null) {return mysqli_query (php7c_mysql_get_link ($link), $query);} // These functions take the mysqli_result object as a parameter. define ('MYSQL_ASSOC', MYSQLI_ASSOC); //these constants have retained the same values (1, 2, 3) define ('MYSQL_NUM', MYSQLI_NUM); //redefine them as they may be used for mysql_fetch_array define ('MYSQL_BOTH', MYSQLI_BOTH); function mysql_data_seek ($result, $offset) {return mysqli_data_seek ($result, $offset);} function mysql_fetch_array ($result, $result_type=MYSQL_BOTH) {return mysqli_fetch_array ($result, $result_type);} function mysql_fetch_assoc ($result) {return mysqli_fetch_assoc ($result);} function mysql_fetch_lengths ($result) {return mysqli_fetch_lengths ($result);} function mysql_fetch_row ($result) {return mysqli_fetch_row ($result);} function mysql_fetch_object ($result, $class_name='stdClass', $params=null) {return mysqli_fetch_object ($result, $class_name, $params);} function mysql_free_result ($resultnull) {return mysqli_free_result ($result);} function mysql_num_fields ($result) {return mysqli_num_fields ($result);} function mysql_num_rows ($result) {return mysqli_num_rows ($result);} function mysql_numrows ($result) {return mysqli_num_rows ($result);} //https://stackoverflow.com/questions/21269293/mysql-num-rows-vs-mysql-numrows?lq=1 function mysql_result ($result, $row, $field=0) {mysqli_data_seek ($result, $row); $data = mysqli_fetch_array ($result); return $data[$field];} } // Replace ereg with preg_match, and split with preg_split if (!function_exists ('ereg')) { // Turn the ereg pattern (which is not surrounded by /) into a preg pattern. I use ~ as this is less likely // to appear in patterns and need escaping. function php7c_ereg_pattern ($pattern) {return '~' . str_replace ('~', '\~', $pattern) . '~';} function ereg ($pattern, $string, &$regs=null) {return preg_match (php7c_ereg_pattern ($pattern), $string, $regs);} function eregi ($pattern, $string, &$regs=null) {return preg_match (php7c_ereg_pattern ($pattern) . 'i', $string, $regs);} function ereg_replace ($pattern, $replacement, $string) {return preg_replace (php7c_ereg_pattern ($pattern), $replacement, $string);} function eregi_replace ($pattern, $replacement, $string) {return preg_replace (php7c_ereg_pattern ($pattern) . 'i', $replacement, $string);} function split ($pattern, $string, $limit=-1) {return preg_split (php7c_ereg_pattern ($pattern), $string, $limit);} function spliti ($pattern, $string, $limit=-1) {return preg_split (php7c_ereg_pattern ($pattern) . 'i', $string, $limit);} //echo "Eregi replace test: " . eregi_replace ("[Bc]", "Z", "abcabcabc") . "
\n"; //echo "Split test: " . join (", ", spliti ("a", "111a222A333a")) . "
\n"; } // Create this function so that it doesn't cause errors. It's been deprecated since PHP 5.3. if (!function_exists ('set_magic_quotes_runtime')) { function set_magic_quotes_runtime() {} } // This provides a function which can replace preg_replace using the 'e' execution modifier. It first checks that // the e is being used, and if so calls preg_replace_callback with a function involving an eval. I got the function // from https://www.ryadel.com/en/php-fix-warning-preg_replace-e-modifier-no-longer-supported-error-php7/ if (!function_exists ('preg_replace_e')) { // in case this file is included multiple times function preg_replace_e ($pattern, $replacement, $subject, $limit=-1, &$count=null) { $delim = $pattern[0]; //the delimiter eg / or ~ $lastpos = strrpos ($pattern, $delim); //position of last delimitier $epos = $lastpos > 0 ? strpos ($pattern, 'e', $lastpos) : 0; //position of e modifier if (!$epos) return preg_replace ($pattern, $replacement, $subject, $limit, $count); //normal replace // See https://www.ryadel.com/en/php-fix-warning-preg_replace-e-modifier-no-longer-supported-error-php7/ else return preg_replace_callback( substr_replace ($pattern, '', $epos, 1), //the pattern without the e function($m) use ($replacement) { //a function to replace the $0 and \1 etc modifiers $rep = $replacement; for ($i=0; $i\n"; }