Error Mysql PHP connection

Asked

Viewed 201 times

0

Good evening, everyone,

I am trying to connect my wordpress application to the remote database, so I can list users within the application.

I already tested some things between some researches, but I could not solve the problem yet.

Can anyone tell me what’s wrong with the code?

I’m using the following code:

<?php
define('hostname', 'http://thorpeinnovation.com/painfree/');
define('user', 'admin');
define('password', 'senha');
define('databaseName', 'osmoc913_wp786');
$connect = mysqli_connect(hostname, user, password, databaseName, 80) or trigger_error(mysql_error(),E_USER_ERROR);

$query = sprintf("SELECT name FROM wp2n_frm_items");

$dados = mysql_query($query, $connect) or die(mysql_error());

$linha = mysql_fetch_assoc($dados);

$total = mysql_num_rows($dados);
?>

<html>
    <head>
    <title>Exemplo</title>
</head>
<body>
<?php

    if($total > 0) {
        do {
?>
            <p><?=$linha['name']?> </p>
<?php
        }while($linha = mysql_fetch_assoc($dados));
    // fim do if 
    }
?>
</body>
</html>
<?php
mysql_free_result($dados);
?>

And it’s returning these errors:

Warning: mysqli_connect(): (HY000/2005): Unknown MySQL server host 'https://thorpeinnovation.com/painfree/wp-content/plugins/wp-phpmyadmin-extension/lib/phpMyAdmin_nwuP' (0) in /home/osmoc913/public_html/thorpeinnovation.com/painfree/wp-content/plugins/insert-php-code-snippet/shortcode-handler.php(65) : eval()'d code on line 6

Fatal error: in /home/osmoc913/public_html/thorpeinnovation.com/painfree/wp-content/plugins/insert-php-code-snippet/shortcode-handler.php(65) : eval()'d code on line 6

1 answer

1


You must inform the address of the database (your hostname), which may be a domain, but should not contain http or paths.

define('hostname', 'thorpeinnovation.com');

If it does not work try to inform the IP address of the server.

Another thing is the function mysqli_connect, which can receive the port of the database, but it is almost never the port 80 as reported, try to change to port 3306

$connect = mysqli_connect(hostname, user, password, databaseName, 3306)

It is also valid to note that the SQL query does not seem to pull user names, unless you use a table with a different default name.

By default Wordpress uses the table PREFIX_users, in your case probably wp2n_users, column-named user_nicename.

Based on this, you may have to change the line below as well.

$query = sprintf("SELECT name FROM wp2n_frm_items");

As last tips, you don’t need this sprintf on the line above, you can only use:

$query = "SELECT name FROM wp2n_frm_items";

Also note that you use functions mysqli in some places and in other capacities mysql, try to use the variants of mysqli if possible always (mysqli_query, mysqli_fetch_assoc, mysqli_num_rows).

Source: https://usersinsights.com/wordpress-user-database-tables/

  • Now you changed the error, it says access is denied. Warning: mysqli_connect(): (28000/1045): Access denied for user 'admin'@'50.116.87.234' (using password: YES) in /home/osmoc913/public_html/thorpeinnovation.com/painfree/wp-content/plugins/Insert-php-code-snippet/shortcode-Handler.php(65) : Eval(code’d on line 6

  • Incorrect password or user without permission to the database.

  • 1

    Look for a file called wp-config.php at the root of the server, it should contain your wordpress database data.

  • I’m using Wordpress 5.1.1 in the web version. Can you tell me more precisely where this file is in the project? Because someone else commented on him before, and I still can’t find him.

  • 1

    At the root of your server, when connecting to the server by ftp you or should see a list of files where one of them is the wp-config.php or you should view a list with a folder called public_html or www, if you see any of these folders the file is probably inside the folder.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.