1

can some one please tell me if these's a problem in my code

$db->orderBy('date','asc');
$schedules = $db->get("schedules");

by having these 2 lines on my page, my page shows Error 500 and if i test it on my computer on Localhost it looks fine and works perfectly. and don't know if the problem is my code or it is server side.

Thanks.

This is my code to connect to database

<?php

$db_host = "HOST";
$db_username = "USERNAME";
$db_password = "PASSWORD";
$db_name = "NAME";

$con = @mysqli_connect("$db_host","$db_username","$db_password","$db_name");

if(!$con)
{
    echo"
    <html>

        <head>
            <meta charset='UTF-8'>
        </head>

        <h1>Can't Connect to database</h1>
    </html>";
    exit;
}
?>
user3600217
  • 69
  • 2
  • 14
  • What does the error log say? – Ro Achterberg Feb 22 '20 at 18:04
  • @RoAchterberg it says " HTTP ERROR 500 " – user3600217 Feb 22 '20 at 18:06
  • @RoAchterberg " PHP Fatal error: Uncaught Error: Call to a member function orderBy() on null in /home/admin/web/site/public_html/page.php:12\nStack trace:\n#0 {main}\n thrown in /home/admin/web/site/public_html/page.php on line 12 " – user3600217 Feb 22 '20 at 18:08
  • Looks like $db is wrong / null. Have you edit your db config for your server? – davidev Feb 22 '20 at 18:09
  • @davidev i did not edit anything sir. my db is external not in same server. and i been using it since long time didn't this issue it just appeared – user3600217 Feb 22 '20 at 18:11
  • @davidev can you please tell me what is $db ? – user3600217 Feb 22 '20 at 18:12
  • @user3600217 Looks like your connection to your database as object. I would need more code. – davidev Feb 22 '20 at 18:14
  • @davidev sir, i have just added my connection code on my question check it out please – user3600217 Feb 22 '20 at 18:18
  • Thanks @user3600217 Why is it called $con and thereafter you use $db? – davidev Feb 22 '20 at 18:20
  • @davidev it is not database sir because even if i put the first 2 lines of php code in an empty page that i posted in my question , it shows that error. only that 2 lines shows that problem but on my localhost it works perfectly – user3600217 Feb 22 '20 at 18:24
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/208331/discussion-between-davidev-and-user3600217). – davidev Feb 22 '20 at 18:25
  • Please avoid using error supression. `@` – Dharman Feb 22 '20 at 21:43
  • Does this answer your question? [Reference - What does this error mean in PHP?](https://stackoverflow.com/questions/12769982/reference-what-does-this-error-mean-in-php) – Dharman Feb 22 '20 at 21:44

0 Answers0