php returns different mysql result - php

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);

Related

Can't access PostgreSQL with PHP

I've been trying to connect to my database, which has been created with PostgreSQL. However, it's unsuccessful.
I've watched lots of videos and researched quite a bit on here, but my issue seems too simple to be an issue for others.
The setup:
I'm hosting a local MAMP (free version) server, in order to use PHP.
I've downloaded and created a database using PostgreSQL locally, and am doing it from pgAdmin 4.
The code is written in a .php file, surrounded by PHP clamps, and the first print line is visible, so I believe there is a connection to the web page in my chrome browser.
I don't get any response from my if-else statement or the pg_query. All the page shows is: This is it:
Issue in short: What is the cause of me not being able to connect to the database and get data from it?
print "This is it:";
$db_connection = pg_connect("host=localhost dbname=first_creation user=postgres password=1234");
if($db_connection)
{
echo "connected";
}
else {
echo "not working";
}
$result = pg_query($db_connection, "SELECT text_content FROM strings");
you need to instll and configure the driver of pgsql in php.ini, please check the following question: How do I enable php to work with postgresql?

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.

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 MySQL with PHP

I have MySQL running such that I can open a client command line and log on and make databases, tables, etc.
I wanted to do some AJAX. Doing AJAX with ASP, SQL Server, etc is not advisable since both places where I am hosting my websites do not use the Microsoft products. So I am forced to do my development with PHP and MySQL.
I just about have everything set up. I have set up IIS so that I can go to my localhost and I can test out web pages. I have PHP installed so that I can pull up the PHP setting pages.
The problem occurs when I try to bring up the MySQL database in PHP. I use this very simple PHP command:
<?php
$con = mysql_connect('localhost', 'testuser', 'testpassword');
?>
When I try to connect to the mysql database through PHP, I get this error:
Click here
I figure the problem must be in the settings that are in the php.ini. But it seems that my php.ini is set up for MySQL although it is not mentioned in the output when I query the phpinfo page with this code
Here is the result from this:
Click here
It looks that your php is missing mysql module
in php.ini make sure that you have correct extensions path eg.:
extension_dir = "C:\php\ext"
and make sure you have commented out:
extension=php_mysql.dll
extension=php_mysqli.dll
Which version of PHP are you running and are you sure you have MySQL installed and running on localhost with a username of "testuser" and a password of "testpassword" (and have you reloaded the privilege tables after creating those users)?
Have you got IIS configured to log errors into a file - does that provide any more information?
Create a new PHP file that contains the following:
<?php
phpinfo();
?>
This will helpy you to discover if MySQL has been compiled in properly etc. Can you access the MySQL server from the command line; using something similar to:
mysql -u testuser -ptestpassword testdatabase
If you get a prompt from MySQL, the service is running and we can better help from there.
Hope that helps a little!
Are you selecting the database? After your connect statement, you need to use:
mysql_select_db($databaseName, $conn);
Documentation here: http://php.net/mysql_select_db
What I would do is to download the complete package in one go (Server, MySQL and PHP). There are tons of good resources like WAMP or MAMP (for MAC users). Once you download the package the installation is just easy and you don't have to set anything as it does it automatically.
They also have phpMyAdmin where you can manage your database and its users and privileges.
Once you got your server running you can test that code that seems fine for me. Try running something like this:
<?php
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected';
mysql_close($link);
?>
Cheers

Categories