Mysql -> mysqli
HejJeg søger hjælp til at opgradere mine mysql kald til mysqli
Alle mine queries kommer fra nedenstående funktioner, så tænker at jeg kan nøjes med at ændre koden i disse funktioner.
Håber at kunne få hjælp til at lave det om til mysqli objekt orienteret
Her er kaldet
// Establish mySQL database connection
$link = dbconnect($db_host, $db_user, $db_pass, $db_name);
unset($db_host, $db_user, $db_pass);
Og herunder er de funktionerne.
// MySQL database functions
$mysql_queries_count = 0;
$mysql_queries_time = array();
function dbquery($query) {
global $mysql_queries_count, $mysql_queries_time; $mysql_queries_count++;
$query_time = get_microtime();
$result = @mysql_query($query);
$query_time = substr((get_microtime() - $query_time),0,7);
$mysql_queries_time[$mysql_queries_count] = array($query_time, $query);
if (!$result) {
echo mysql_error();
return false;
} else {
return $result;
}
}
function dbcount($field, $table, $conditions = "") {
global $mysql_queries_count, $mysql_queries_time; $mysql_queries_count++;
$cond = ($conditions ? " WHERE ".$conditions : "");
$query_time = get_microtime();
$result = @mysql_query("SELECT Count".$field." FROM ".$table.$cond);
$query_time = substr((get_microtime() - $query_time),0,7);
$mysql_queries_time[$mysql_queries_count] = array($query_time, "SELECT COUNT".$field." FROM ".$table.$cond);
if (!$result) {
echo mysql_error();
return false;
} else {
$rows = mysql_result($result, 0);
return $rows;
}
}
function dbresult($query, $row) {
global $mysql_queries_count, $mysql_queries_time;
$query_time = get_microtime();
$result = @mysql_result($query, $row);
$query_time = substr((get_microtime() - $query_time),0,7);
$mysql_queries_time[$mysql_queries_count] = array($query_time, $query);
if (!$result) {
echo mysql_error();
return false;
} else {
return $result;
}
}
function dbrows($query) {
$result = @mysql_num_rows($query);
return $result;
}
function dbarray($query) {
$result = @mysql_fetch_assoc($query);
if (!$result) {
echo mysql_error();
return false;
} else {
return $result;
}
}
function dbarraynum($query) {
$result = @mysql_fetch_row($query);
if (!$result) {
echo mysql_error();
return false;
} else {
return $result;
}
}
function dbconnect($db_host, $db_user, $db_pass, $db_name) {
global $db_connect;
$db_connect = @mysql_connect($db_host, $db_user, $db_pass);
mysql_set_charset('utf8');
$db_select = @mysql_select_db($db_name);
if (!$db_connect) {
die("<strong>Unable to establish connection to MySQL</strong><br>".mysql_errno()." : ".mysql_error());
} elseif (!$db_select) {
die("<strong>Unable to select MySQL database</strong><br>".mysql_errno()." : ".mysql_error());
}
}