3

I have database table options, where am using it as a dedicated table to store information. I have never heard of this type of table query and have never tried it. I saw on WordPress database so thought to try my own.

Here's database table

enter image description here

This is what am trying now

$sql = "SELECT * FROM options WHERE option_flag = 'settings'";
var_dump( $db->FETCH_FIELD($sql) ); 

This is inside my database class file $db

public function FETCH_FIELD($sql){
    $this->results = mysqli_query($this->link, $sql);       
$rows = mysqli_fetch_fields( $this->results );
    return $rows;
}

The Problem

When I var_dump the results, I don't see any database information.

enter image description here

1

1 Answer 1

3

Since you want to get an array that shows the query results, I would try this:

<?php
$db = new mysqli(HOST, USERNAME, PASSWORD, DBNAME);
$stmt = $db->query("SELECT * FROM options WHERE option_flag = 'settings'");
$result = $stmt->fetch_all();
var_dump($result);

Of course, this works in procedural style, too:

<?php
$link = mysqli_connect(HOST, USERNAME, PASSWORD, DBNAME);
$stmt = mysqli_query($link, "SELECT * FROM options WHERE option_flag = 'settings'");
$result = mysqli_fetch_all($stmt);
var_dump($result);

Go to the php documentation to learn more about mysqli_result::fetch_all.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.