I am currently working with mysql_connect() even though it’s use is discouraged. My web service does not support PDO. I currently had my code formatted into PDO but now i have been forced to change it to mysяl_connect(). After these changes now I am receiving a page error and nothing displays. I am including a database_connect.php that is working with another page just not with my adapted code. What is the issue in my code that is causing this error? Here is my PAGE
Code
include ('./snippets/db_connect.php');
$query = ("SELECT class_name, class_caption, class_credit_hours, class_description
FROM class
");
$query->execute();
if ($query->execute()){
$totalhours = 0;
while ($row = mysql_fetch_assoc( $query )){
print "<b>" . $row['class_name'] . "</b><br>";
print $row['class_caption'] . "<br>";
print $row['class_description'] . "<br>";
print $row ['class_credit_hours'] . "hrs. <br>";
print "------------------------------<br />";
$totalhours += $row['class_credit_hours'];
}
print "<p>Total hours for Major: " . $totalhours . ".</p>";
"<div> </div>"
$queryis jsut a string, so there is noexecutemethod. You never callmysql_query($query). so there is no result set.Also if your host doesn’t support PDO you should switch, even if you arent planning on using it. There is no excuse for them not to support it at this point in time, it was made standard in php 5.1, and your host should at least have php 5.2.17 available if not the current stable of 5.3.
Now, if you know PDO you might want to try
Mysqliinstead ofext/mysql. Its more like PDO and supports prepared statments and what not. Your host should at least have that. If they dont then double emphasis on changing hosting providers.