Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?PHP
- //in my header file that is included on every page I have this
- $DB["dbName"] = "emails";
- $DB["host"] = "localhost";
- $DB["user"] = "root";
- $DB["pass"] = "";
- $link = mysql_connect($DB['host'], $DB['user'], $DB['pass']) or die("<center>An Internal Error has Occured. Please report following error to the webmaster.<br><br>".mysql_error()."'</center>");
- mysql_select_db($DB['dbName']);
- // end header connection part
- // function from a functions file that I run a mysql query through in any page.
- function executeQuery($sql) {
- $result = mysql_query($sql);
- if (mysql_error()) {
- $error = '<BR><center><font size="+1" face="arial" color="red">An Internal Error has Occured.<BR> The error has been recorded for review</font></center><br>';
- if ($_SESSION['auto_id'] == 1) {
- $sql_formatted = highlight_string(stripslashes($sql), true);
- $error .= '<b>The MySQL Syntax Used</b><br>' . $sql_formatted . '<br><br><b>The MySQL Error Returned</b><br>' . mysql_error();
- }
- die($error);
- }
- return $result;
- }
- // example query ran on anypage of the site using executeQuery function
- $sql='SELECT auto_id FROM friend_reg_user WHERE auto_id=' .$info['auto_id'];
- $result_member=executequery($sql);
- if($line_member=mysql_fetch_array($result_member)){
- extract($line_member);
- } else {
- header("location: index.php");
- exit;
- }
- ?>
- mysql_query($query)
- mysqli_query($link, $query)
- //local
- $sql_host = "localhost";
- $sql_username = "root";
- $sql_password = "";
- $sql_database = "db";
- $mysqli = new mysqli($sql_host , $sql_username , $sql_password , $sql_database );
- /* check connection */
- if ($mysqli->connect_errno) {
- printf("Connect failed: %sn", $mysqli->connect_error);
- exit();
- }
- // /* change character set to utf8 */
- if (!$mysqli->set_charset("utf8")) {
- printf("Error loading character set utf8: %sn", $mysqli->error);
- exit();
- } else {
- // printf("Current character set: %sn", $mysqli->character_set_name());
- }
- if (!function_exists('mysql_real_escape_string')) {
- function mysql_real_escape_string($string){
- global $mysqli;
- if($string){
- // $mysqli = new mysqli($sql_host , $sql_username , $sql_password , $sql_database );
- $newString = $mysqli->real_escape_string($string);
- return $newString;
- }
- }
- }
- // $mysqli->close();
- $conn = null;
- if (!function_exists('mysql_query')) {
- function mysql_query($query) {
- global $mysqli;
- // echo "DAAAAA";
- if($query) {
- $result = $mysqli->query($query);
- return $result;
- }
- }
- }
- else {
- $conn=mysql_connect($sql_host,$sql_username, $sql_password);
- mysql_set_charset("utf8", $conn);
- mysql_select_db($sql_database);
- }
- if (!function_exists('mysql_fetch_array')) {
- function mysql_fetch_array($result){
- if($result){
- $row = $result->fetch_assoc();
- return $row;
- }
- }
- }
- if (!function_exists('mysql_num_rows')) {
- function mysql_num_rows($result){
- if($result){
- $row_cnt = $result->num_rows;;
- return $row_cnt;
- }
- }
- }
- if (!function_exists('mysql_free_result')) {
- function mysql_free_result($result){
- if($result){
- global $mysqli;
- $result->free();
- }
- }
- }
- if (!function_exists('mysql_data_seek')) {
- function mysql_data_seek($result, $offset){
- if($result){
- global $mysqli;
- return $result->data_seek($offset);
- }
- }
- }
- if (!function_exists('mysql_close')) {
- function mysql_close(){
- global $mysqli;
- return $mysqli->close();
- }
- }
- if (!function_exists('mysql_insert_id')) {
- function mysql_insert_id(){
- global $mysqli;
- $lastInsertId = $mysqli->insert_id;
- return $lastInsertId;
- }
- }
- if (!function_exists('mysql_error')) {
- function mysql_error(){
- global $mysqli;
- $error = $mysqli->error;
- return $error;
- }
- }
- $sql_host = "your host";
- $sql_username = "username";
- $sql_password = "password";
- $sql_database = "database";
- $mysqli = new mysqli($sql_host , $sql_username , $sql_password , $sql_database );
- /* check connection */
- if ($mysqli->connect_errno) {
- printf("Connect failed: %sn", $mysqli->connect_error);
- exit();
- }
- function mysql_query($query){
- $result = $mysqli->query($query);
- return $result;
- }
- function mysql_fetch_array($result){
- if($result){
- $row = $result->fetch_assoc();
- return $row;
- }
- }
- function mysql_num_rows($result){
- if($result){
- $row_cnt = $result->num_rows;;
- return $row_cnt;
- }
- }
- @mysql_connect($host, $username, $password) or die("Error message...");
- @mysql_select_db($db);
- @mysql_connect($host, $username, $password, $db) or die("Error message...");
- $con = mysqli_connect($host, $username, $password, $db) or die("Error message...");
- function my_function(...) {
- global $con;
- ...
- }
- mysql_connect ---> mysqli_connect
- mysql_select_db ---> mysqli_select_db
- mysql_error ---> mysqli_connect_error()
- mysql_query ---> mysqli_query
- mysql_fetch_assoc ---> mysqli_fetch_assoc
- $conn = mysqli_connect($db_host, $db_username, $db_password, $db_name) or die("Unable to Connect");
Add Comment
Please, Sign In to add comment