gamerguy90 gamerguy90 - 8 months ago 31
MySQL Question

Trying to access stored procedure in PHP from MySQL

So I created a stored procedure in phpMyAdmin named "Ratio_Viewer". It takes in one parameter which is a stock ticker. I tested it in phpMyAdmin and I received the correct tuples. Now I am trying to incorporate that into my php files. I have a page where you enter a ticker and it takes you to another page which is supposed to display you the data based upon the stock ticker I entered. Nothing is getting returned. My code is

require 'connection.php';
$sql = "CALL Ratio_Viewer('" . $_REQUEST["ticker"] . "')";

if(!$result = $mysqli->query($sql)) {
echo "error: " . $mysqli->error . "<br>";


echo ($result->fetch_assoc());


Your code is working.

echo ($result->fetch_assoc());

will simply print "Array". PHP does not print arrays in a readable format in this case.

You can use print_r or var_dump or implement a loop to print the data you want. For example,

foreach ($result->fetch_assoc() as $k => $v) echo "$k is $v <br>";

Your code is vulnerable to SQL injection.