Trying to pull mysql data but put it in as php variables

So currently I’m trying to put data from mysql into a php variable. This is mainly because I don’t want to have to go back and change everything that has a variable into the mysql variable, and I’ve been getting errors. I was wondering if there was anything I could do to get this work?

This is what I was trying to do, I also tried a few variants of this and the only big issue I was getting was “Uncaught Error: Cannot use object of type mysqli_result as array” Which makes me think this is basically impossible and I gotta stop being lazy.

$HOST= mysqli_fetch_assoc($result[‘host’]);

I don’t get what you have and what you want to achieve and why.

I’m trying to pull info from a database. so for example my database has id,username,password,host. know I want to pull information from that database and put it as a php variable suck as $HOST.

The end result would be if I put

<?php echo '$HOST;' ?>

or whatever the correct line of code would be it would echo the information from the mysql table that is under host.

I currently have all of this information setup in a config file and am working on moving it over to a mysql table and want to know if I can do this.

Hi,
you need to change your code to:

$row = mysqli_fetch_assoc($result);
$HOST = $row['host'];
1 Like

man y’all are some magical people… Thank you very much

Sponsor our Newsletter | Privacy Policy | Terms of Service