Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

heropaulexy's avatar

Database Crash

My database suddenly crashed returning 'Error: localhost via TCP/IP'

I don't know how to fix it

0 likes
12 replies
automica's avatar

I dont think anyone else will be able to either unless you specify what db it is and how you are accessing it.

heropaulexy's avatar

It's a SQL database. My SQLi

''' public function __construct(){ $this->pdo = new PDO('mysql:host=localhost;port=3306;dbname=scandiweb_product_crud', 'root', '');

    $status = $this->pdo->getAttribute(PDO::ATTR_CONNECTION_STATUS);

    if($status === 'mysql:host=localhost;port=3306;dbname=scandiweb_product_crud') {
        echo "Connection Successful!";
    } else {
        echo "Error: " . $status;
    }

}

'''

Tray2's avatar

@heropaulexy Have you tried logging in from the terminal?

If that works, try changing the localhost to 127.0.0.1

heropaulexy's avatar

@Tray2 this was what it returned

The term 'mysql' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

Urvin's avatar

@heropaulexy This error usually come when SQL server not accepting TCP/IP Connection, pls try below steps it will work for sure.

1)open run and add command SQLServerManager15.msc 2)click on network configuration then "protocols for MSSQLSERVER" 3)Select protocol name - "TCP\IP" and make sure that it is enable if not then pls make it enable. 4)Check the property and find port in IP address tab.

Restart the server, it should work

1 like

Please or to participate in this conversation.