I've started converting all my old websites from MySQL to MySQLi. The issue I'm having is that some functions I use have stopped working and also files that are "included" or use a config file (with the connection) are not successfully connecting. I found an answer on here on how to make a connection.
EXAMPLE
config.php
class DBi {
public static $db;
}
DBi::$db = new mysqli('host', 'uname', 'pword', 'database');
if ($db->connect_error) {
die('Connect Error (' . $db->connect_errno . ') '
.$db->connect_error);
}
search-autocomplete-business-names.php
<?
require_once ('config.php');
if (!isset($_REQUEST['term'])) {
exit;
} else {
$rs = DBi::$db->query('SELECT...');
$data = array();
if ($rs && $rs->num_rows) {
while($row = $rs->fetch_assoc()) {
$busname = htmlspecialchars_decode($row['BName'], ENT_QUOTES);
$label = $busname;
$data[] = array(
'label' => $label,
'value' => $row['BName']
);
}
}
echo json_encode($data);
flush();
}
?>
Javascript that uses the above include
<script>
<!-- business name autocomplete -->
$(function() {
$(".src-bn").autocomplete({
type: "POST",
source: "lib/search-autocomplete-business-names.php",
minLength: 1,
focus: function(e, t) {
return $(".src-bn").val(t.item.label), $(".src-spc").val(t.item.value), !1
},
select: function(e, t) {
return $(".src-bn").val(t.item.label), $(".src-spc").val(t.item.value), !1
}
}).data("ui-autocomplete")._renderItem = function(e, t) {
return $("<li>").append("<a>" + t.label + "</a>").appendTo(e)
}
});
</script>
What I want is to be able to create a connection that I can run in any file, whether it's a main page, within a function or an included file. Any ideas please? Thank you in advance.
G