Forum Moderators: open

Message Too Old, No Replies

Data missing in phpmyadmin, but PHP script still returns it

         

dougmcc1

5:28 am on Mar 6, 2017 (gmt 0)

10+ Year Member



I have a php script that is pulling data correctly from a database table which I created in phpmyadmin and also inserted 2 rows into using phpmyadmin. All of a sudden though, the 2 rows in the table went missing in phpmyadmin. It shows an empty result set when I go to the Browse tab. But the php script still returns the 2 rows from this table, even in multiple browsers including browsers I hadnt run the script in prior to this issue (confirming that the discrepancy is not due to browser caching).

So it seems like the data is still there - and theres no reason it shouldnt be since there's no code in the php script that would remove these rows and I didnt remove them manually in phpmyadmin and there's no one else that has access to the database or the script.

But the question is why does phpyadmin show this table is empty when the script is still returning data from it? And actually, there are 2 other tables that have the same issue where data from the tables are missing in phpmyadmin but the script still returns all the data that was originally there.

There's no issue with the code, since its returning the data correctly. The issue seems to be with phpmyadmin not showing the data that is there. Any idea how that could be?

topr8

8:03 am on Mar 6, 2017 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



have you got different database users who have different permissions? and are you perhaps not logging in with the same username that your script is using to connect.

phranque

9:54 am on Mar 6, 2017 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



make sure phpadmin is using the right database (as opposed to a copy - such as the development/staging db, for example)

dougmcc1

2:00 pm on Mar 6, 2017 (gmt 0)

10+ Year Member



Thanks for the replies.

topr8 - when I log into phpmyadmin its through cpanel as the root user. The php script does use a different user to connect to the database. However, both users have all permissions. Could the different users "See" the database differently?

phranque - is it possible that the php script is connecting to a different copy of the database than phpmyadmin? I wouldnt know how to look into this but I connect to the localhost server in php. Could phpmyadmin be connecting to something else than localhost which might contain a different version of the database? Here's how I'm connecting to the database in php:


define('DB_SERVER','localhost');
define('DB_NAME','(database)');
define('DB_USER','(username)');
define('DB_PASSWORD','(password)');
$dbh=mysql_connect (DB_SERVER, DB_USER, DB_PASSWORD) or die ('System is down. We apologize for the inconvenience. Please try again soon.' . mysql_error());
mysql_select_db (DB_NAME);
$query="SELECT DISTINCT(username) FROM users";
$result=mysql_query($query);
if (!$result = mysql_query($query))
{
// There was an error in the sql statement
print "there was an error in the sql statement, ".mysql_error()."<br><b>$query</b>";
exit;
}
while ($row = mysql_fetch_array($result)) {
extract($row);


The way I get to phpmyadmin is I log into whm as the root user, go the accounts list, click into the account, then click into phpmyadmin. The url for phpmyadmin looks like this:
https :// 999.99.99.999:9999/cpsess8446873464/3rdparty/phpMyAdmin/index.php#PMAURL-0:index.php?db=&table=&server=1&target=&lang=en&collation_connection=utf8_general_ci&token=fcef24bffdb3e90c1f8a45d86aab5c3d

phranque

2:15 pm on Mar 6, 2017 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Could phpmyadmin be connecting to something else than localhost which might contain a different version of the database?

can't you see the server connection settings in phpmyadmin?
do yo have access to the server such that you can see the phpmyadmin config file?

dougmcc1

3:18 pm on Mar 6, 2017 (gmt 0)

10+ Year Member



Ah, yes I found this in phpmyadmin:

Database server
Server: Localhost via UNIX socket
Server type: MySQL
Server version: 5.5.54-cll - MySQL Community Server (GPL)
Protocol version: 10
User: cpses_adT5yB3Swf@localhost
Server charset: UTF-8 Unicode (utf8)

I also found this:
Server: localhost:3306

And this:
Web server
cpsrvd 11.62.0.16
Database client version: libmysql - 5.1.73
PHP extension: mysqli

I also found the config file. It contained some of the same information as above:
$cfg['Servers'][$i]['host'] = 'localhost';
$cfg['Servers'][$i]['port'] = '3306';

topr8

3:24 pm on Mar 6, 2017 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



if you can't tell, why not add another row using phpmyadmin and then see if it shows using your php script.
if it does then, we know the database is the same for a start at least.

topr8

3:34 pm on Mar 6, 2017 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



also why don't you run the query (that you use in your php script) directly in phpMyAdmin, there's a tab called 'sql'

there's a good chance your browser has weirdly cached the 'browse' tab page

lammert

5:10 pm on Mar 6, 2017 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



According to your URL, phpMyAdmin doesn't connect to a database or table when you initially connect: "...db=&table=&..." You should check the URL when you are actually browsing the table with the missing records. The URL contains the database and table it browses with a URL like:

https://example.com/sql.php?server=1&db=your_database&table=your_table&pos=0&token=some_token

dougmcc1

8:16 pm on Mar 6, 2017 (gmt 0)

10+ Year Member



topr8 - I added a new row and it did not show up in the php script. Which is good because it tells me that the data that got deleted from the tables in phpmyadmin still exists Somewhere. Wherever the php script is still pulling it from. I'd like to find it so I can populate the tables again in phpmyadmin. Also, running the query from the php script in the SQL tab yields the same result as the going to the Browse page.

lammert - I went to phpmyadmin in another browser (starting from WHM, then the account, then cpanel, then phpmyadmin) and here's the url I get on the Browse page:
https :// 999.99.99.999:9999/cpsess4779400671/3rdparty/phpMyAdmin/index.php#PMAURL-1:sql.php?db=my_database&table=users&server=1&target=&token=7d5fb6951382c269ec94e337db75bb56