|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
PHP Gives Me an Invalid MySQL Resource
If someone could help me out, it would be most appreciated... I am working against a deadline, and this error is driving me crazy.
I have a simple MySQL query, as shown below: $CreativeCalendars = mysql_pconnect($hostname_CreativeCalendars, $username_CreativeCalendars, $password_CreativeCalendars) || die(mysql_error()); mysql_select_db('ccdb1') || die(mysql_error()); $mysql_result = mysql_query("SELECT code FROM giftcertificateorders") || die(mysql_error()); The above mysql_query returns the integer 1 every time--not 'resource id #1'. So when i try and use $mysql_result in mysql_fetch_assoc() or the like, i get a 'supplied argument is not a valid MySQL result resource' every single time. Yet none of my die(mysql_error()) functions are triggered. I have double-checked my spelling and the like about twelve times. I can even enter the exact same query into the MySQL Query Browser, and it works fine. Someone help... please... |
|
#2
|
|||
|
|||
|
No one ever replied? I have practically the same issue - I have the following PHP (just a snippet):
Code:
$current_player = mysql_fetch_assoc($result);
$lastseen = "SELECT last FROM users WHERE name='$current_player[name]'";
$last = mysql_query($lastseen) or die(mysql_error());
echo "$lastseen <br> $last <br>";
if($last < time() - 30) {
My echo statement is just for my troubleshooting purposes. The entire bit is within a for statement, looping through each item retreived via $result - when I echo $lastseen, it produces a valid MySQL query: Code:
SELECT last FROM users WHERE name=' TheRUNaway' And running that query through phpMyAdmin produces the desired result: 1124544537 However, my if statement ALWAYS proves true, and the echo of $last simply shows "Resource id #8" - like the other poster said, my die statement never produces an error. As I said, this is within a for statement - when I echo the output for troubleshooting, I just wind up with a list like: Quote:
Sorry for digging up such an old post, but this is one that really has me stumped (need I add that I am VERY new to PHP & MySQL - this is code written originally by someone else, I'm trying to add this additional query & the if statement), and all I'm finding are unanswered posts when I Google it. |
|
#3
|
|||
|
|||
|
As usual, the moment I give up and yell for help, I find the answer. Posting for the next person:
Everything was fine in the above code, except - In my query, I had to "SELECT * FROM .. " Stored the query as $last_result, then: $last = mysql_fetch_assoc($last_result) Then I could call the 'last' field that I needed with: $last[last] |
![]() |
| Viewing: Dev Articles Community Forums > Databases > Database Development > PHP Gives Me an Invalid MySQL Resource |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|