1

Upgraded word press version to latest version 4.3.1 and custom queries are not working into word press Upgrade. It's give message like "no database selected".

All the database details in wp-config.php are correct and working fine before up grade. following custom query which is gives message to me after upgrading to 4.3.1 latest version.

Please help to fixing it.

$sql = "select Country_Id, Country_Code,Country_Name from mopt_country where IsActive=1 order by Country_Name ASC";

$result = mysql_query($sql) or die(mysql_error());   
Happy Coding
  • 2,517
  • 1
  • 13
  • 24
Ni3
  • 65
  • 1
  • 9
  • 1
    Fistly, Are you trying to implement WP into another page which isn't WP ?? Secondly,What's the purpose of that sql code?? Be more clear please to help you – Greg Nov 25 '15 at 07:13
  • 1
    An error "db no found" is a "db not found" error, but explain us if it occurs on the actual WP website, or to another custom page which you hook some WP function. – Greg Nov 25 '15 at 07:13
  • Trying to implement into which is WP pages here. I don't wants to use WP standard quries as it's previously working fine. – Ni3 Nov 25 '15 at 07:15

1 Answers1

0

Can you use mysqli which is safer and not deprecated like mysql function? I had some connection problem when I used the mysql function. Dunno why honestly.

here is a sample code

    $mysqli = @new mysqli($DBServer, $DBUser, $DBPass, $DBName);
    if(!mysqli_connect_errno())
    {
        mysqli_set_charset($mysqli,"utf8");

        $sql = "            
                SELECT param1,...,param9
                FROM Table
                ";

        if($stmt = $mysqli->prepare($sql))
            {
                $stmt->execute();
                $stmt->bind_result($param1,...,$param9);
                while ($stmt->fetch())
                {   
                    //your code
                }
            }
        $mysqli->close();       
    }
    else
    {
        echo 'Unable to connect';
        exit();
    }

Post your results after it.

Also, as I have already said in my comments, a no db problem is a no db problem. Double check your creditians (user, pass, dbname).

It seems logic after the upgrade, WP add any extra column or delete any column, but it doesn't logic to change your db name.

Edited:

Probably, this is the reason that you have that error:

check that link: Why shouldn't I use mysql_* functions in PHP?

As you can see, Quentin says that :

  • The "new" password authentication method (on by default in MySQL 5.6; required in 5.7)
  • All of the functionality in MySQL 5.1
Community
  • 1
  • 1
Greg
  • 343
  • 3
  • 17
  • My all database details are correct and using mysqli it's working but there is lots of changes need to perform into every pages which is too much time consuming.I din't updated PHP or Mysql version so there should not be display such message like "No Database Selected". Is any another solution for it ? – Ni3 Nov 25 '15 at 08:18
  • I don't imagine any other solution. Wait for a couple hours if anyone has any other solution. However, you have to keep in mind if you don't update your php regularly, maybe a future version of Wordpress may not be compatible with the old php version. – Greg Nov 25 '15 at 08:28
  • Yes. I do understand yours but for now as an quick solution I want to implement here. I have planned to change it into mysqli into future. – Ni3 Nov 25 '15 at 08:33
  • 1
    If my answer is worked for you and helped to give you more details about your issue, feel free to "tick it" as answer! Cheers! @Rocker – Greg Nov 26 '15 at 01:19
  • Actually it's not my expected answer. The same was I already tried. – Ni3 Nov 26 '15 at 07:14