PHP MySQL connect, insert, select data from advanced version…

$dbHost = ‘localhost’;
$dbUsername = ‘root’;
$dbPassword = ”;
$dbName = ‘db_name’;
//Connect with the database
$db = new mysqli($dbHost, $dbUsername, $dbPassword, $dbName);

if ($db->connect_errno) {
printf(“Connect failed: %s\n”, $db->connect_error);
/*Get data from table*/
$accounts = $db->query(“SELECT * FROM table_name”);

while($row = $accounts->fetch_assoc()){
echo $row[‘sub_id’];

/*Store data in table*/

$query = “INSERT INTO table_name VALUES (‘$str’)”;
$sql = $db->query($query);


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s