0

So I took a website which is currently live and transferred everything to my computer so I can work on it locally. I am in the process of getting everything working locally but can't get my MySQL queries to work. I am connected to a database which is identical to the original database that the website was running on.

The error I'm getting is: Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in... (yes I am going to move everything to mysqli once I get this working)

I've tested very simple queries and had no luck. Here is one I tried:

<?php
$con = mysql_connect('localhost', 'root', null, 'database_name') or die("Could not connect.");
echo mysql_result(mysql_query("SELECT `data` FROM `test-table` WHERE `id` = 0"), 0);
?>

Does this have something to do with the fact that I am running locally?

I'm running this on WAMP, Apache/2.4.2 (Win64) PHP/5.4.3

hal
  • 4,845
  • 7
  • 34
  • 57
  • 3
    Are you sure that your local MySQL server has a `root` user with no password? – Explosion Pills Oct 09 '13 at 16:43
  • The boolean is probably `false` from a failure somewhere in the middle of your call chain on the second line. Try splitting out each call individually and testing for individual errors. – PaulProgrammer Oct 09 '13 at 16:46
  • 2
    Your 4th parameter in `mysql_connect()` is wrong, it should be Boolean. However, it would be correct if you were using the MySQLi extension instead. – Jason Oct 09 '13 at 16:52
  • I think the problem is that you are not selecting the database. As mentioned above 4th parameter is wrong. You have to call mysql_select_db after you established the connection – rovski Oct 09 '13 at 17:02

1 Answers1

2

You need to use mysql_select_db('database_name') instead of incorrectly passing the database name to the mysql_connect function.

See the manuals:

If I were in the process of updating from mysql_* to mysqli_* I would first change my functions then debug as it will save from doing debugging only to change it and debug again. Just a thought...

amaster
  • 1,915
  • 5
  • 25
  • 51