Jump to content
xisto Community
leiaah

Trouble With Mysql

Recommended Posts

I just bought a book 'SAMS Teach Yourself PHP, MySQL, and Apache' and it included a CD with installers of the 3. I previously had MySQL 3.23.54 on my computer and since there's a newer version in the CD I replaced it with that one. Everything worked fine and I even set permissions for users using the windows command prompt but the trouble came when I try previewing the pages I have. Nothing gets displayed when I view it in a browser (no tables, no error on the connection, nothing). I know that PHP works fine because I've tested out some PURE PHP pages, the only trouble is the PHP pages with MySQL queries. The pages worked fine when I uploaded them on my Xisto website but not here in my local PC. Does anyone know what's wrong with it and what has to be done about it?

Share this post


Link to post
Share on other sites

Make sure the PHP scripts are connecting to the DB and selecting the DB okay. Try to do something like

$username = 'something';$password = 'something';$dbname= 'something';mysql_connect ("localhost", $username, $password) or die ('ERROR: I cannot connect to the database because: ' . mysql_error());mysql_select_db ($dbname) or die ('ERROR: I cannot select the database because: ' . mysql_error());

And die() messages further along the way as well.

Share this post


Link to post
Share on other sites
@ $db = mysql_connect ("localhost", "xxxx", "xxxxx") or die ('I cannot connect to the database because: ' . mysql_error());mysql_select_db ("blog",$db); if(!$db){	echo 'Could not connect to the database';	exit;}mysql_select_db('blog');$query=mysql_query("SELECT name,url,msg,id FROM shout  ORDER BY id DESC",$db) or die (mysql_error());while($row=mysql_fetch_row($query)){                //echo the results here}

Bjrn...

This is the code I use and nothing gets displayed still. I reinstalled the older version of MySQL that worked for me before but still nothing. I'm thinking maybe it has to do with the PHP version I have now installed or the Apache server.

Share this post


Link to post
Share on other sites

Perhaps if you tried this:

mysql_connect ("localhost", "xxxx", "xxxxx") or die ('I cannot connect to the database because: ' . mysql_error());mysql_select_db ('blog) or die ('I cannot select the database because: ' . mysql_error());$query=mysql_query("SELECT name,url,msg,id FROM shout  ORDER BY id DESC",$db) or die (mysql_error());while($row=mysql_fetch_row($query)){echo "Name: ".$row[0];}

Things you might want to check:
I'm sure you've checked yourself, but I still have to ask: Are you completely sure that there is data in the shout table?

That you aren't using mysql_fetch_row() and then $row['name']. I think when you fetch results with the row function, you can only use numbers, if you want to use names like: $row['name'], $row['url'] etc, you have to use mysql_fetch_array($query) instead.


That's all I can think of right now.

Share this post


Link to post
Share on other sites

Maybe your pc just cant process mysql, you may just access it through your Xisto website, since it wont do much harm... and maybe its not called localhost, but I'm not really sure, cause I never tried using mysql through my pc...

Share this post


Link to post
Share on other sites

Or maybe try updating your PHP version? I don't know, it may help, it may not, it probably has nothing to do with it, but, *shrug* there's a possibility it could work.

Share this post


Link to post
Share on other sites
mysql_select_db ("blog",$db);

if this is on the Xisto server, your database name should start with prefix(mostly your cpanel username) e.g. this format "username_blog".
even though you can use "blog" as a database name on local server but on Xisto must have username prefix.

:rolleyes:

Share this post


Link to post
Share on other sites

Leeiah - most likely your copy of PHP is still using the authentication method that was used in MySQL 3.x. This is a very common problem. MySQL 4.1 and later uses a new authentication protocol which is not compatible with the libraries that PHP 4 uses.

 

First try setting the option display_errors to 1 in your php.ini file, and restart php+your system. When display_errors is set to 1, it instructs PHP not to suppress error messages - that will help in spotting the exact nature of the problem.

 

Next try your own php code again and see if it gives out an error like "Client does not support authentication protocol" - that is a sureshot sign of this. Now your job would be to update PHP to the latest version (5) and update your MySQL too.. and restart the system. That should ideally solve your problem. You might also consider removing the "@" in front of your $db = mysql_connect, temporarily for debugging purposes.

 

From what I've seen in your case - I'm damned sure its the older PHP version causing this problem.

 

Try and let me know - or else, will tell you another solution (a little brute force way)...

 

Regards,

m^e

Edited by microscopic^earthling (see edit history)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.