Copy link to clipboard
Copied
I have a dynamic web site which works without problems on the local host. Using phpMyAdmin I exported the database to a sql file. All web page files were transferred to the on-line host using Dreamweaver CC.
On the on-line host (using Plesk) I ran phpMyAdmin on the on-line host and used the import facility. The database I was using locally appears to have loaded correctly to the on-line area as I can see it using phpMyAdmin..
However, any page which does not make use of the database displays coerrectly on line but any page that should display data from any table on the database fails.with either a "Not found" error or more commonly "The website cannot display the page".
Being very much a newby when it comes to dynamic sites I feel I have missed something obvious! It works on the local host but not the on-line host despite both having access to the same database. (I think!).
Thanks.
Ian
Copy link to clipboard
Copied
Seems like an obvious question, but are your pages connecting to the database? For example, the code below is what I use to call one of my databases. I am using PDO here. If you are using SQLi, your code would be different. If you are using MySQL. . .well, you shouldn't be!
Also note that the connection script should be in a file by itself and stored above the web root, where it will be more difficult to hack into. Note that the file name below begins with a period. Thats a further security measure. Each page needing the database will have code like the following at the top (within PHP script tags:
require_once '../database/.site_pdo.php';
<?php
$dsn ='mysql:dbname=database_1;host=localhost;port=3306';
$user='username';
$password='password';
try {
$dbh = new PDO($dsn, $user, $password);
//$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT);$dbh->query=("set names utf8");
$dbh->exec('SET CHARACTER SET utf8');
$dbh->exec('SET character_set_server=utf8');
}
catch (PDOException $e) {
die('Connection failed: '.$e->getMessage());
}
Another thing to note about the script above is that ERRORMODE_SILENT is set for the remote webiste, so visitors and hackers won't see error messages, and for your local site you would comment that out and uncomment ERRORMODE_EXCEPTION, so that you do see the errors during development. This is very important for PDO. I'm not sure about SQLi.
Copy link to clipboard
Copied
I'm struggling to get to grips with SQL - don't confuse a silver surfer with yet another language!!
I think you have highlighted the problem. I thought it wasn't accessing the database for some reason and I tried to see if I could get it to work on my laptop. I copied the site and database over to that and got a "No database selected" error which confirms your thoughts. Now I have to figure out why. There is a connection script but it would seem it isn't conecting.
Thanks for the help Rob.
Ian
Copy link to clipboard
Copied
The connection script you use on the remote server and the one for your local server may not be the same. Your web hosting company may be able to provide you with the correct parameters to use for the remote system. Make sure you are using the correct username and password.
SQL is not difficult and is easy to test, so don't worry too much about it.
If you are not using PDO or MySQLi, but the legacy mysql connection instead, then you should seriously consider switching to MySQLi as soon as you can. The legacy mysql conection has been deprecated and there are many good reasons not to use it.
Copy link to clipboard
Copied
Thanks - will do both!
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more