Output of SQL query as variable PHP

General Tech Bugs & Fixes . 2 years ago

  0   2   0   0   0 tuteeHUB earn credit +10 pts

5 Star Rating 5 Rating

Posted on 16 Aug 2022, this text provides information on Bugs & Fixes related to General Tech. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Write Your Comments or Explanations to Help Others



Tuteehub forum answer Answers (2)


profilepic.png
manpreet Tuteehub forum best answer Best Answer 2 years ago

I have a PHP script that connects to one of my SQL databases and runs a select command. I'm then trying to see what the output is of command but when I f="https://forum.tuteehub.com/tag/echo">echo my results to a file I get "Resource id #f="https://forum.tuteehub.com/tag/5">5" and not a path like I'm expecting. Can anyone tell me where I'm going wrong, I suspect it is the query or the result variable but I'm pretty new to php.

$connection = mysql_connect("127.0.0.1", "user", "f="https://forum.tuteehub.com/tag/password">password");

if(!$connection) {
    system("f="https://forum.tuteehub.com/tag/echo">echo 'ERROR! Unable to connect to MYSQL' >> /Reports/sqlerror");
}

$dbselect = mysql_select_db("mydatabase");


$query = "select p.path from path as p f="https://forum.tuteehub.com/tag/join">join file as f on p.pathid=f.pathid where f.filename like '$xfilename' and p.path like '/Data/original%'";

$result = mysql_query($query);


mysql_close($connection);

system("f="https://forum.tuteehub.com/tag/echo">echo '$result' >> /Report/sqloutput");
0 views   0 shares
profilepic.png
manpreet 2 years ago

Found the answer. Needed to use mysql_fetch as below.

$query = mysql_query("select p.path from path as p join file as f on p.pathid=f.pathid where f.filename like '$xfilename' and p.path like '/Data/original%'");

$f="https://forum.tuteehub.com/tag/result">result = mysql_fetch_row($query); system("echo '$f="https://forum.tuteehub.com/tag/result">result**[0]**' >> /Report/sqloutput");


0 views   0 shares

No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.

tuteehub community

Join Our Community Today

Ready to take your education and career to the next level? Register today and join our growing community of learners and professionals.

tuteehub community