Hello. I connect DB using the code:

<? function db_connect() { $host = 'localhost'; $user = 'shop_user'; $pswd = 'admin123'; $db = 'shop'; $connection = mysql_connect($host, $user, $pswd); if (!$connection || !mysql_select_db($db, $connection)) { return false; } return $connection; } function db_result_to_array() { $res_array = array(); $count = 0; while ($row = mysql_fetch_array($result)) { $res_array[$count] = $row; $count++; } return $res_array; } function get_products() { db_connect(); $query = "SELECT * FROM products ORDER BY id DESC"; $result = mysql_query($query); $result = db_result_to_array($result); return $result; } ?> 

It produces the following error:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in D:\appserver\www\shop\db_fns.php on line 25

Help, please, what needs to be fixed?

    1 answer 1

    Well, first of all, where is the code itself, where do you call your functions ?? .By how you predosavili file with functions, they themselves until they are not caused by the error does not give.

    BUT from what you presented - you have an error in the db_result_to_array () function, perches it like this:

     function db_result_to_array($result) { $res_array = array(); $count = 0; while ($row = mysql_fetch_array($result)) { $res_array[$count] = $row; $count++; } return $res_array; }