configure DSN when uploading to server - php

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.

Related

Hard time to connect to my database with php

I am trying to build a homne server for studies on a raspberry pi 3.
I am just trying to connect to my raspberry database and php base to use my database on a HTML page.
I tried everything 9not apparently), to change several times my login, i tried with 'root' and create an other user and give all privileges etc, but nothing seem to work. I have all installed, php work just fine, i can reach my server with a domain name hosted by noip. the html and php content pop just fine.
I can even connect to my database via ssh.
But since few month i tried to make it work and i am desesperate, so if someone can help me ...
<?php
$db = mysqli_connect("mywebsite","root","myLogin","mydbName")
or die(mysqli_error($db));
?>
so i would just be able to make request on my database, i am just blocked on that step
$con=new mysqli("localhost","root","root_password","database_name");
Generally, root has no password so the connection should be like this
$con=new mysqli("localhost","root","","database_name");

How to setup Database connection using php coding and where to save that file?

I am having some problems with php coding i have written php coding correct but it is not working,it is giving an error that "The Object not found" in browser.
Hey guyz please help me i am stuck on this and tried every possible thing to make this coding work.
Thanks
First php is not supported by itself in browser, you need a server to run php,you can use a localhost server like wamp, create DB in phpMyAdmin panel with the desired username and password then you can connect to it from your classes.
$this->host="localhost";
$this->username="root";
$this->password="";
$this->database="dbname";
$con=mysql_connect($this->host,$this->username,$this->password) or die(mysql_error());
$res=mysql_select_db($this->database,$con)or die(mysql_error());
you can save the file in any folder but it is advisable for u to save it in where all your files are kept for a quick reference.
below is php code for setting up database:
$con=mysqli_connect("host","user","password") or die(mysqli_error());
mysqli_select_db($con,"yourdatabasename");
Note:
host=localhost(if wamp or xampp is used) or your domain name(like www.google.com)
You can save dis php file with any name e.g config.php.
user= username of your database used in your phpmyadmin. likewise your password.
If you are using wamp or xampp, use dis format:
$con=mysqli_connect("locahost","root","") or die(mysqli_error());

php can connect remotely to mysql but not locally

UPDATE:
I tried having my php file in windows and connect to the mysql server remotely in linux using the code below
mysql_connect('10.128.xx.xx', 'jflim', 'helloworld');
this works! but when i tried uploading the same php file in linux(server) and changing the connection string to
mysql_connect('localhost', 'root', '');
its not working.. its also not showing any error message. php codes are working fine without database connection. Im not sure what the problem is now. many thanks
If you upload the .php file in the server where the mysql server is running you should use 'localhost'. But if the script is located in another machine replace the 'localhost' with an ip address or url (www.example.com).
Apart from that, make sure you use the right username and pw.

Defining PHP Constants - What Is My Server Name?

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)

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