Forum Moderators: coopster

Message Too Old, No Replies

Problem with mysql stuff?

         

tacteanh

8:32 am on Jul 8, 2005 (gmt 0)

10+ Year Member



I've got this file to connect to my database to get some value.
============================
dbcon_test.php
============================
<?php
$link = mysql_connect ("localhost", "abc_dbadmin", "abc_password")
or die ("Could not connect to MySQL Database");
mysql_select_db("abc_mydb", $link);

$sql = "select * from tbltest";
echo "SQL: " .$sql ."<Br>";
$result = mysql_query($sql);
$totalRecords = mysql_num_rows($result); // <-- This is line 9
echo "<br>Total records: " .$totalRecords;
?>
=============================

and it works well on my localhost and some other free host.
But now i've just bought a hosting package and have the following result when i browse to dbcon_test.php.

======================
SQL: select * from tbltest

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home2/abc/public_html/dbcon_test.php on line 9

Total records:
================================

It seems to be no record in my database, but acctually when i try the same query in the phpMyAdmin of THAT HOST. It's still run well and show me the result of that query.

Somebody help me.
Thank you.

buriedUnderGround

12:23 pm on Jul 8, 2005 (gmt 0)

10+ Year Member



change this line:
$result = mysql_query($sql);
to
$result = mysql_query($sql) or print(mysql_error());

if this is where the problem is, the
print(mysql_error()) should tell you exactly what's going wrong. You can add this after any mysql function to help with your debugging process.

ergophobe

4:56 pm on Jul 8, 2005 (gmt 0)

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



Very strange. My addition to the above suggestion would be to turn PHP error_reporting to max (E_ALL) and see if you get any undefined variables or anything like that.

You can do this in php.ini or simply at the top of the script by adding the line

error_reporting(E_ALL);

tacteanh

5:41 pm on Jul 8, 2005 (gmt 0)

10+ Year Member



Thank you all of you. My problem was solved.

The reason sounds strange and silly but it was like this:

I've written an email and send to my hosting provider to tell them about my problem and ask they check my hosting configuration.

After all, they sent me an email and said that they have a problem with their mysql server but it's ok now. I check my website again and it works, great isn't it :o)

But now i'm thinking about their answer. If they have a problem with their mysql server, so why i still can do the queries in their phpMyAdmin, which still return the right results!?!?!
Strange!

ergophobe

5:58 pm on Jul 8, 2005 (gmt 0)

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



That's the part that's bizarre to me. Both are accessing the server via PHP. The only thing I can think of is that they were denying from some domains and... ah I don't know. At least it's fixed.