Back to Knowledge Base
Knowledge Base Web Hosting How to test MySQL connection?

How to test MySQL connection?

Web Hosting 07/11/2026
<p><span style="font-family: arial, helvetica, sans-serif; font-size: small;">Solution</span></p>
<p><span style="color: #333333; font-family: monospace; font-size: 12px;">&lt;?php<br />$connection= mysql_connect('hostname','dbuser','dbpassword');<br />if (!$connection) {<br />die('Could not connect to MySQL: ' . mysql_error());<br />} else {<br />echo 'Connection OK';<br />}<br />mysql_close($connection); ?&gt;</span></p>
Was this article helpful?