Mysql table fetch using php agi

hello team.
I want to fetch mysql database fields row with help of php agi but some issues, please help me to fetch database field.

php agi

$db = ‘’;
$dbuser = ‘root’;
$dbpass = '
’;
$dbhost = ‘localhost’;
$dbCon = mysqli_connect($dbhost,$dbuser,$dbpass) or die (“could not connect to mysql”);
mysqli_select_db($dbCon, “$db”) or die(“could not open database”);
$query = “SELECT * FROM quizivr2 WHERE callerId = ‘$mobileno’”;
$query2 = “SELECT questionId,language,score FROM quizivr2 WHERE callerId = ‘$mobileno’”;
if($result=mysqli_query($dbCon, $query)) {
$score_percent = array_values(mysqli_fetch_assoc($result));
}
#mysqli_free_result($result);
mysqli_close($dbCon);

*here as output I need result all fields value or row.
pls see

Please post code, configuration, and log snippets in 'Preformatted text' tags.

This snippet does not interact with Asterisk, thus, this is a PHP problem, not an Asterisk problem. You may find more appropriate help on a PHP forum. PHP is not my strongest suit, but here’s my $0.02.

This is a bad idea.

Why are you converting a perfectly good associative array to a plain boring array?

It seems much easier and robust to access values by column name instead of an arbitrary numerical index that is subject to change. For example:

echo 'as an associative array ' . $score_percent['timestamp'] . PHP_EOL;

vs

echo 'as a plain boring array ' . $score_percent[42] . PHP_EOL;

What happens when you hire a ‘sort everything alphabetically’ kind of guy like me and I add a column named 'timefordinner' before 'timestamp'?

Before executing this script as an AGI, try getting it running as a shell console application. It will be easier to debug.

thanks for reply,
I tried many times but still not getting required answers, pls see.
$query = “SELECT callerId,callerId FROM quizivr2 WHERE callerId = ‘$mobileno’”;
if($result=mysqli_query($dbCon, $query)) {
$score_percent = $score_percent[‘level’];

$agi->set_variable(“SCORE_PERCENT”, $score_percent);

would be more helpful if you give complete command line to implement
thanks

Seriously.

Did you try? What did you learn? Please show the shell console output.

Once you have your PHP errors (there are at least 2 in the snippet you posted) resolved, add the AGI bits back in. If the AGI does not work, try the Asterisk CLI command 'agi set debug on' for clues.

It would, but this (forum) isn’t that.

This forum is to help you learn to fish, not hand you a fish. If you just want the fish, break out your checkbook. I’ll be more than willing to help :slight_smile:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.