mysql test error

  • Zealous
  • Guru
  • Guru
  • User avatar
  • Posts: 1244
  • Loc: Sydney

Post 3+ Months Ago

I have been working though a php book and so i am working on this part that you need to test the mysql test and i am checking my work as i can not figure out this small mistake i have missed to get the script working, i have missed something small but not sure what it is.

Code: [ Select ]
<?
/* Program: mysql_test.php
* Desc:  Connects to MYSQL Server abd outputs settings.
*
*/
echo "<html>
   <head><title>Test Mysql</title></head>
   <body>";
$host="localhost";
$user="user";
$password="password";

$cxn = mysqli_connect($host,$user,$password);
$sql="SHOW STATUS";
$result = mysqli_query($cxn, $sql);
if($result == false)
{
echo "<h4>Error: ".mysqli_error($cxn)."</h4>";
}
else
{
  /* Table that displays the results */
echo "<table border='1'>
   <tr><th>Variable_name</th>
   <th>Value</th></tr>";
for($i = 0; $i < mysqli_num_rows($result);$i++)
{
echo "<tr>";
$row_array = mysqli_fetch_row($result);
for($j = 0;$j < mysqli_num_feilds($result);$j++)
{
echo "<td>".$row_array[$j]."</td>\n";
    }
  }
echo "<table>";
}
?>
</body></html>   
  1. <?
  2. /* Program: mysql_test.php
  3. * Desc:  Connects to MYSQL Server abd outputs settings.
  4. *
  5. */
  6. echo "<html>
  7.    <head><title>Test Mysql</title></head>
  8.    <body>";
  9. $host="localhost";
  10. $user="user";
  11. $password="password";
  12. $cxn = mysqli_connect($host,$user,$password);
  13. $sql="SHOW STATUS";
  14. $result = mysqli_query($cxn, $sql);
  15. if($result == false)
  16. {
  17. echo "<h4>Error: ".mysqli_error($cxn)."</h4>";
  18. }
  19. else
  20. {
  21.   /* Table that displays the results */
  22. echo "<table border='1'>
  23.    <tr><th>Variable_name</th>
  24.    <th>Value</th></tr>";
  25. for($i = 0; $i < mysqli_num_rows($result);$i++)
  26. {
  27. echo "<tr>";
  28. $row_array = mysqli_fetch_row($result);
  29. for($j = 0;$j < mysqli_num_feilds($result);$j++)
  30. {
  31. echo "<td>".$row_array[$j]."</td>\n";
  32.     }
  33.   }
  34. echo "<table>";
  35. }
  36. ?>
  37. </body></html>   
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9099
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

What is the error you are receiving?
  • Zealous
  • Guru
  • Guru
  • User avatar
  • Posts: 1244
  • Loc: Sydney

Post 3+ Months Ago

Code: [ Select ]
Warning: mysqli_connect() [function.mysqli-connect]: (28000/1045): Access denied for user 'lampp'@'localhost' (using password: YES) in /opt/lampp/htdocs/phpland/mysql_test.php on line 13

Warning: mysqli_query() expects parameter 1 to be mysqli, boolean given in /opt/lampp/htdocs/phpland/mysql_test.php on line 15

Warning: mysqli_error() expects parameter 1 to be mysqli, boolean given in /opt/lampp/htdocs/phpland/mysql_test.php on line 18
Error:
  1. Warning: mysqli_connect() [function.mysqli-connect]: (28000/1045): Access denied for user 'lampp'@'localhost' (using password: YES) in /opt/lampp/htdocs/phpland/mysql_test.php on line 13
  2. Warning: mysqli_query() expects parameter 1 to be mysqli, boolean given in /opt/lampp/htdocs/phpland/mysql_test.php on line 15
  3. Warning: mysqli_error() expects parameter 1 to be mysqli, boolean given in /opt/lampp/htdocs/phpland/mysql_test.php on line 18
  4. Error:

was up late last night forgot to add it.
  • WritingBadCode
  • Graduate
  • Graduate
  • User avatar
  • Posts: 214
  • Loc: Sweden

Post 3+ Months Ago

Quote:
Warning: mysqli_connect() [function.mysqli-connect]: (28000/1045): Access denied for user 'lampp'@'localhost' (using password: YES) in /opt/lampp/htdocs/phpland/mysql_test.php on line 13


This could be that you are providing the wrong username/password to access the database. Do a double check to see that you have entered the right values (is lampp the correct username etc).


The second error I think I see is a simple typing error, you wrote:

for($j = 0;$j < mysqli_num_feilds($result);$j++)

correct is:

for($j = 0;$j < mysqli_num_fields($result);$j++)

Also for comparability I read somewhere its better to avoid: <? and use <?php instead. But that's just what I read.
  • Zealous
  • Guru
  • Guru
  • User avatar
  • Posts: 1244
  • Loc: Sydney

Post 3+ Months Ago

oh snap, never saw that error i was like wtf could be wrong. Good find

hhmm i guess i could do that, if it helps then even better. cheers mate.

Post Information

  • Total Posts in this topic: 5 posts
  • Users browsing this forum: No registered users and 121 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.