Mysql_select successfully exits, returns null

As a complete php / sql noob, I tried to configure very simple on the server. I have a db with a table and I am trying to read it on a php page. Here is the relevant part of my code:

<?php $con = mysql_connect("localhost", "----", "----") or die(mysql_error()); mysql_select_db("my_db") or die ("Select db fail!"); $ings = mysql_query($con, "SELECT * FROM Table") or die("Query fail: " . mysql_error()); mysql_close($con); ?> 

Output:

 Query fail: 

I can’t circle my head. mysql_error does not return anything. I tried mysql_errno and it returns 0 , I tried mysql_num_rows($ings) and returns nothing.

Any insight?

+4
source share
1 answer

The signature for mysql_query only accepts the query string ... you do not need to pass the connection because it is established in the background.

A stamp is called because the function call is not valid, so the error is empty because the request never starts.

And yes, mysql_query is deprecated in favor of mysqli . You could also study it from the very beginning, so you do not need to study it twice.

+5
source

Source: https://habr.com/ru/post/1482237/


All Articles