Defining PHP Constants - What Is My Server Name? - php

I have:
<?php define('DB_SERVER', 'localhost')
If I put this constants.php file on my web host's server, is it still 'localhost'? Or something else.
I use hostmonster.com for my website. Does that replace localhost?

Yes, you should still use 'localhost' to connect to the database server.
Have a look at the hostmonitor help, 'Using the database'.
https://my.hostmonster.com/cgi/help/6
Using the Database
After doing all these steps, create the database's tables either via
phpMyAdmin, MySQL software or use an online PHP or Perl script.
Version: MySQL 5
Username: username_dbuser
Database Name: username_dbname
Hostaddress: localhost
Port: 3306
Obviously, use your own database username and database name :)
(The ones you got when creating the database)

It's a string. A simple, hardcoded string. It won't magically change, because it's not a variable. 'localhost' will always be 'localhost'.

No, it doesn't. You define here a PHP constant, not a value that comes from server's headers (localhost)

Related

Php code not executing on web browsers [duplicate]

I just did a fresh install of Apache server 2.2.
Everything works. When I go to localhost I get: "It Works!"
I just installed mySQL5.5 and when I go to localhost:3306 I just get gibberish:
J���
5.5.22�'���4[LM{D~p�ÿ÷!�€����������6[I=4/+,9z{|�mysql_native_password�!��ÿ„#08S01Got
packets out of order
I see many posts on the internet with users with similar problems, but I can't figure out a solution.
Can anyone help?
The mysql service is not a web interface - you cannot connect using a browser. You will need to install a mysql client of some kind.
If you try to start phpmyadmin then do it like this:
localhost/phpmyadmin
I'm a jsp beginner.
I have a same problem with you.
I guess it's kind of port problem.
For me, I had set the port for Apache server connector as 9090.
Later, when I installed mysql, the port for mysql was 3306 as its default port.
In my jsp file,
i loaded jdbc driver like 'jdbc:mysql://localhost:9090/dbname'
and then i call 'http://localhost:9090/my.jsp' on my web browser.
That's when I got the same problem with you.
I fixed the port part in my jsp file like 'jdbc:mysql://localhost:3306/dbname'
and I could get it all right.
I think you need to check the port for your Apache server.
You can check out \conf\server.xml file in your Apache directory.
The part starts with "Connector port=8080...." in server.xml file.
If so, you need to put 'http://localhost:8080... on your browser.
Try just to write http://localhost/ without the port and it will work , Or go to your phpmyadmin and click on My websites and it will take you immediately to your localhost
I'm having exactly the same problem, so far I have :
1)Manually changed the Collation (it seemed to be defaulting to cp850)
2)altered the ini/cnf file (located under services.msc -> MySQL)
3)Changed the max_packet_size to 2G
3)rebooted the server.
As a start to this please run this script from MySQL
'SHOW VARIABLES WHERE Variable_name LIKE 'character_set_%' OR Variable_name LIKE 'collation%';'
It should bring up a table of your collations, they should all read utf8
Possible causes

PHP - MySQL Security Issue?

Just wondering is this could be a potential security problem with MySQL and PHP:
I have a connect.php file on a server, if someone used require(http://myurl.com/connect.php/);, would this allow them access to my database?
Thanks in advance
No, but for additional security, it's best to keep your sensitive files outside of the web root, in case a misconfiguration of your webserver breaks PHP and exposes it as plain text.
No, that would not allow them to connect to your database. When they require your connect.php over Internet, they get what is produced by this php script as output. In your case, your php script (connect.php) probably produces nothing as output (it just connects to db and terminates.
No, PHP variables are not accessible client side. For example a file like this
<?php
// Create connection
$con=mysqli_connect("example.com","peter","abc123","my_db");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
The $con variable would not be accessible publicly.
Probably not. If "someone" does require(http://myurl.com/connect.php/); from his server (and has the inclusion via http enabled, see http://www.php.net/manual/en/function.include.php), then his server connects to your server and fetches the interpreted output of your connect.php.
If you have 'server side include' enabled - yes.
Read about allow_url_include directive: http://www.php.net/manual/en/filesystem.configuration.php

configure DSN when uploading to server

I have webpages mostly in PHP, ms sql database and IIS 7 server. Locally it works fine but now I'm trying to upload that to webserver using VPN and Filezilla. The problem is, what do I have to configure to get that working? On webserver there are two folders : one for webpages and one for database files. Do I have to change $host name, $username and $password in file_constants.php, or is there any other configurattions needs to be changed? Please help
I'v read instruction but there is only two lines about that, saying that I must refer to a datasource that tells the server which database to use.
You should change hostname, username, password and database into the values your hosting has given you.

connecting to another db from one server

Ok so I have a client that is trying to move half his site to another server...in this i still need to pull data from both databases. SO i have the new site and i need to do a mysql db query on the old site so i can include the old nav....but when i do
<?php include("http://www.othersite.com/includes/db.php"); ?>
<?php include("http://www.othersite.com/includes/nav.php"); ?>
I get
Warning: mysql_query(): Access denied for user 'www-data'#'localhost'
(using password: NO) in /vol/www/othersite.com/public_html/includes/nav.php
on line 223 Warning:
How do i access another db from the new site and not allow it to interfere with the new db connection
you can use:
$newLink = mysql_connect($host, $user, $password);
mysql_select_db($db, $newLink);
and the you should add the $newLink to your queries so it will not use the "old" database link connection, like:
mysql_query('SELECT * FROM USERS', $newLink);
Hope it helps
P.S. It'll be more easy if you put the code from db.php and nav.php
You'd need to show us the actual code used to connect to these dataases (with passwords blanked out). But even without it I can tell you that the remote server is NOT called localhost.
It seems you're including these files from the remote site. It won't work this way, since the code is still executed on local server.
You must also make sure, that the remote MySQL allows remote connections, and that there is a MySQL user account with appropriate privileges created.
See: http://dev.mysql.com/doc/refman/5.5/en/privilege-system.html
...in this i still need to pull data
from both databases.
Good luck with this!
The way I would do this:
Copy code to server #2
Adjust it to fetch data from server #1
Change DNS record from ip of server #1 to ip of server #2
Wait 1 day
Give blocking 'server maintenance' for 5 minutes on server #1
rsync db from server #2 to #1 / adjust server #2 to fetch data from itself
Remove 'server maintenance'
Sell server #1 on ebay and get boozed
NOTE:
Sure, if you are talking about some private host.. There are far more successful yet complicated mechanisms to do the same without putting server offline.
Load http://www.othersite.com/includes/db.php in your browser. You'll notice that you cannot see the PHP code: what you obtain is the output of the PHP code. That means than changing all your ìnclude constructs to point to a remote HTTP server will simply break your site since you'll no longer have access to the source code.
Now, answering to your question, if you want to connect to a remote database you must find wherever you have the DB password and change the data: localhost with the new server address, www-data with your new user, etc. However, you probably need to configure the remote MySQL server so it accepts external connections from your new server's IP address.

php returns different mysql result

I have just moved my host to another machine but now a problem has occured. I get different mysql results from php. To be more spefecific, php returns the last result when i got back-up. I am checking database via mysql console but there are new entries. But php continues to return the old results. What do i need to do fix this?
P.S i can download php files which are on my new host. I can see the source code. Weird...
Thank you.
Your php might still be connecting to the old database
If you can download the php files, your server isn't set up to run PHP and/or has a mis-configured .htaccess file
Check your database connection code.
It's possible that you're connecting to a remote host, rather than 'localhost':
$mysql_connection = mysql_connect('mysql.example.com', 'user', 'pass');
There is another possibility, different databases:
mysql_select_db('using_old_db', $mysql_connection);

Categories