]{ronic Posted May 26, 2014 Share Posted May 26, 2014 Hi, If I place the following into a file called db.php and save it into folder called includes using xampp: $dbhost = 'localhost';$dbuser = 'root';$dbpasswd = '';$database = 'test'; $connection = mysql_connect("$dbhost","$dbuser","$dbpasswd") or die ("Couldn't connect to server."); $db = mysql_select_db("$database", $connection)or die("Couldn't select database."); and try to access it by adding require_once 'includes/db.php'; into index.php, I get the following error: Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\index.php on line 28 But if I paste the code directly into index.php it works fine.. Both ways work fine using my paid hosting.. Whats going wrong? Thanks Quote Link to comment Share on other sites More sharing options...
PravinS Posted May 26, 2014 Share Posted May 26, 2014 check the SQL query, whose resource id is passed to mysql_fetch_array() function at mentioned line or else show us the code of C:\xampp\htdocs\index.php Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted May 26, 2014 Share Posted May 26, 2014 where is the script of this index file? Quote Link to comment Share on other sites More sharing options...
]{ronic Posted May 26, 2014 Author Share Posted May 26, 2014 (edited) This works: $dbhost = 'localhost'; $dbuser = 'root'; $dbpasswd = ''; $database = 'test'; $connection = mysql_connect("$dbhost","$dbuser","$dbpasswd") or die ("Couldn't connect to server."); $db = mysql_select_db("$database", $connection) or die("Couldn't select database."); $sql = mysql_query("SELECT firstname FROM clients ORDER BY firstname ASC"); while ($row = mysql_fetch_array($sql)) { echo ''.$row['firstname'].'<br />'; } This fails: require_once 'includes/db.php'; $sql = mysql_query("SELECT firstname FROM clients ORDER BY firstname ASC"); while ($row = mysql_fetch_array($sql)) { echo ''.$row['firstname'].'<br />'; } with error: Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\index.php on line 16 I can use require once on other files from the includes folder ok.. Seems to be only the db.php file that plays up. dp.php: <? $dbhost = 'localhost'; $dbuser = 'root'; $dbpasswd = ''; $database = 'test'; $connection = mysql_connect("$dbhost","$dbuser","$dbpasswd") or die ("Couldn't connect to server."); $db = mysql_select_db("$database", $connection) or die("Couldn't select database."); ?> Strange issue, It only fails using xampp locally.. the basic script works fine on other professional servers as it should Edited May 26, 2014 by ]{ronic Quote Link to comment Share on other sites More sharing options...
Solution jazzman1 Posted May 26, 2014 Solution Share Posted May 26, 2014 (edited) Maybe....because you are using a short opening php tag in db,php or dp.php (check the name of that file) instead "<?php"? Edited May 26, 2014 by jazzman1 Quote Link to comment Share on other sites More sharing options...
]{ronic Posted May 26, 2014 Author Share Posted May 26, 2014 Erm Hate that, lost so much time lol.. Thanks Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.