Hosting, servers, etc, usually does not have the MySQL server on the same machine as Apache (where is the php and etc), this is because usually the stations where the database servers are separated, then you must access the panel of your Hosting / VPS or whatever it is and check which HOST or IP is your mysql server.
I recommend reading this: What's the difference between MySQL and phpMyAdmin?
Note that usually even cheaper hosts can have multiple mySql servers, so it would also not make sense to use localhost
as a host.
Usually the server uses a subdomain with its host, for example:
- Site http:
www.site.com
- mysql server:
msql.site.com
This is just an illustrative example, it would usually be something like :
<?php
$hostdb = "mysql.meuservidor123.com";
$userdb = "clientes_assoc";
$passdb = "senha";
$tabledb = "assocs";
$conecta = mysql_connect($hostdb, $userdb, $passdb) or die (mysql_error());
I also recommend not using the mysql_
prefix API it is obsolete, today we have the mysqli
and PDO
APIs, read on at: