I can't to connect my php code with mysql database, but the data of connection are correct

Username: epiz_30963913

php code:

<?php
    class ConexaoDao{
        private $server = "sql103.epizy.com";
        private $user = "epiz_30963913";
        private $pass = "it's private";
        private $db = "epiz_30963913_informatica";

        public function conecta(){
            $conexao = new PDO("mysql:server={$this->server}; dbname={$this->db}; charset=utf8", $this->user, $this->pass);
            return $conexao;
        }
    }
?>

it don’t return error message, but don’t to send data.

Re-check /verify your credentials?

1 Like

yes, i check more 10 times

I haven’t connected to the database in PHP using namespace, etc. But this basic this might be useful. Also, can you enable PHP errors and produce them here?

1 Like

the errors php are enable but don’t return any error, but also don’t return the result of query, i want do a login in my site, but don’t be compare the login data with the user data in database because don’t connect with database, i already did test with this same code in other hosting site and the connection is normal, but here i can not

I’m not the best with PHP, but that looks wrong.

Can you try connecting using mysqli? If you don’t want to, stackoverflow may be a better spot to ask this (You could also wait for someone else as well).

i will try using mysqli, after comeback for say if it’s worked or no. Thank you

i try again with PDO, and return this error:

SQLSTATE[HY000] [2002] No such file or directory, all code are correct.

A quick Google search brings up this:

nothing work, is possible the infinityfree did send me incorrect credentials of mysql?

If you use the MySQL construct does it work?

do want to say mysqli? if yes, i don’t tryed because need change many code lines

1 Like

Well, can you at least write one line of code to see if it will connect? Then we will know if it is your credentials, PDO, or something else.

1 Like

ok, i will try now

i tryed with mysqli, and worked, but why don’t work with PDO?

nothing work, return this in console.

Cross-Origin Read Blocking (CORB) blocked cross-origin response https://infinityfree.net/errors/404/ with MIME type text/html. See Chrome Platform Status for more details.

someone know what’s this?

That’s the security policy

Please note the connection parameters of a PDO DSN for MySQL.

https://www.php.net/manual/en/ref.pdo-mysql.connection.php

I see you’re putting the server name into the parameter server, but that should be host.

Also, I’m not completely sure, but it might also not like the spaces in the DSN.

So I think you should be able to connect successfully with this line instead:

 new PDO("mysql:host={$this->server};dbname={$this->db};charset=utf8", $this->user, $this->pass);
4 Likes