I’m still relatively new to php.
I created a sub folder below my webroot called lib and added test.php
I then added the following code…
<?php
new \Wisdom\Question();
?>
I then created another folder within lib called “Wisdom” and a class called “Question” with the 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 to select database");
$query = "SELECT * FROM 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 I view the test.php in a browser, it just shows an error 500 (on another note, how do I show php errors on screen? I tried ERROR_REPORTING(E_ALL) but it didn’t do anything. But it never shows any of the echos during the db connect. My db has all the fields as expected. Any ideas? Thank you!
A ha, just found out the php version is 5.2 so won’t have namespaces.
Thanks for all the other answers.