/    Sign up×
Bounties /Pin to ProfileBookmark

Assistance needed to modify my code for mysqli

Please can someone assist me to modify the below code to work with to interact with database. I have tried many options, but I keep getting either parameter warnings or errors. The following is my code:


function db_connect(){
    global $data;
        $data['Hostname'], $data['Username'], $data['Password']
    if(!$data['cid'])echo('<font color=#FF0000>'.mysqli_error().'</font>');
    @mysqli_select_db($data['Database'], $data['cid']);
    return (bool)$data['cid'];

function db_disconnect(){
    global $data;
    return (bool)@mysqli_close($data['cid']);

function db_query($statement){
    global $data;
    return @mysqli_query($statement, $data['cid']);

function newid(){
    global $data;
    return @mysqli_insert_id($data['cid']);

function db_count($result){
    return (int)@mysqli_num_rows($result);

function db_rows($statement){
    for($i=0; $i<$count; $i++){
        $record=@mysqli_fetch_array($query, MYSQLI_ASSOC);
        foreach($record as $key=>$value)$result[$i][$key]=$value;
    return $result;

Please let someone with good knowledge of mysqli help me out.

to post a answer

3 Replies

Davinci•003 auto-replyIf you are looking for assistance with modifying your code for mysqli, the best place to start is by reading the official documentation. The mysqli documentation provides detailed information on how to use the mysqli functions and classes. Additionally, there are many tutorials and examples online that can help you understand how to use mysqli.

For example, the following code snippet shows how to use the mysqli_query() function to execute a query:

$mysqli = new mysqli("localhost", "my_user", "my_password", "my_db");

/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %sn", mysqli_connect_error());

$query = "SELECT Name, CountryCode FROM City ORDER by ID DESC LIMIT 10";

if ($result = $mysqli->query($query)) {

/* fetch associative array */
while ($row = $result->fetch_assoc()) {
printf ("%s (%s)n", $row["Name"], $row["CountryCode"]);

/* free result set */

/* close connection */


Was this helpful?

Copy linkTweet thisAlerts:
@akluch2authorApr 26.2023 — The code I posted is from a script I purchased long ago. It was working on my website with mysql until my hosting company upgraded server to higher php version. Now I am trying to modify the code to work with the php version using mysqli. I am not too good with the new mysqli. For few days now I have looked at many tutorials I can find on the internet and tried to modify the code with what I learned, but it has not worked. Please I need help.
Copy linkTweet thisAlerts:
@akluch2authorApr 26.2023 — I have solved the issue now. I was able to understand parameter with help of proper explanation from the site https://lxadm.com/mysqli_query-expects-parameter-1-to-be-mysqli/

Thanks all.


Help @akluch2 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.15,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ

legal: ({
terms: of use,
privacy: policy
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,