oop - How does php output to screen + using mysql to show values on screen? -
i'm still relatively new php.
i created sub folder below webroot called lib , added test.php
i added following code...
<?php new \wisdom\question(); ?>
i created folder within lib called "wisdom" , class called "question" following code...
<?php class question { function __construct() { $user="username"; $password="password"; $database="dbname"; mysql_connect(localhost,$user,$password); @mysql_select_db($database) or die( "unable select database"); $query = "select * questions"; $result = mysql_query($query); $num = mysql_numrows($result); mysql_close(); echo "<b><center>database output</center></b><br><br>"; $i=0; while($i < $num) { $description = \mysql_result($result,$i, "description"); $id = \mysql_result($result,$i, "id"); echo "<b>$id $description</b>"; $i++; } }
}
when view test.php in browser, shows error 500 (on note, how show php errors on screen? tried error_reporting(e_all) didn't anything. never shows of echos during db connect. db has fields expected. ideas? thank you!
from question it's not easy kind of error facing. 500 internal server error can have multiple reasons. can php concerned about, can webserver well.
so best answer can give configure php error handling / php error configuration , check php error log.
in parallel need check webservers error log well.
next that, these thoughts had because of code posted, might misleading:
what try achieve needs autoloader enabled. looks class \wisdom\question
not exists when try instantiate it:
new \wisdom\question();
the autoloader needed load non-existent classes directory/file-layout seem use (i can't because question not give more information).
for autoloader looks can use autoloader psr-0 compatible, for example one.
next that, class definition needs correct namespace on top:
<?php namespace wisdom; class question {
Comments
Post a Comment