I connect the database to the site, but throws an error.

Warning: mysql_fetch_array () expects parameter 1 to be resource, given in C: \ OpenServer \ domains \ ProbaSite \ index.php on line 4

Error screenshot:

enter image description here

I would like to make a reservation in advance what I did for the lesson (it may be old and I will not be able to provide links to it because they threw files at me), PHPMyAdmin was used there, but I want to connect via SQL Maestro. I do everything through the Open Server.

Code file index.php

<?php include ("blocks/bd.php"); $result=mysql_query("SELECT title,meta_d,meta_k,text FROM settings WHERE page='index'",$db); $myrow = mysql_fetch_array($result); ?> <!DOCTYPE html> <html> <html> <head> <meta name="description" content="<?php echo $myrow['meta_d']; ?>"> <meta name="keywords" content="<?php echo $myrow['meta_k']; ?>"> <meta charset="windows-1251"> <title><?php echo $myrow['title']; ?></title> <link rel="stylesheet" href="style.css"> </head> <body> <table width="700" border="0" align="center" cellpadding="0" sellspacing="0" bgcolor="#FFFFFF" class="main_border"> <? include ("blocks/header.php"); ?> <tr> <td><table width="700" border="0" cellpadding="0" sellspacing="0"> <tr> <?include ("blocks/left.php"); ?> <td valign="top"> <?php echo $myrow['text']; ?> </td> </tr> </table></td> </tr> <? include ("blocks/footer.php"); ?> </table> </body> </html> 

Bd.php file code

 <?php $db=mysql_connect ("localhost","root"); mysql_select_db ("MyWork",$db); ?> 

    2 answers 2

    Check whether the sql server is running at all. Try to display the value of $result most likely there is false . From there it is possible and error
    It is better to do something else. In the bd.php file

     $db=mysql_connect ("localhost","root"); if (!$db) { die(mysql_error()); } 

      Initially, my Open Server did not start, because its MySql and mine were on the same port 3306 and I had to rearrange it MySql to 3309. By trial and error, I came to the conclusion that OpenServer still uses its default MySlq and not mine. As a result, the solution was to disable MySql-I Open Servera and to return in its settings to port 3306.