I use the following fragment of code to output datf from MySQL:
=============== =============== =============== =========
$chan = mysql_connect ($db_host, $username, $password);
mysql_select_db ($DB_name, $chan);
$resultid = mysql_query ("select name_ru, description_ru, retail, dealer
from lasershot WHERE le='1'", $chan);
........
=============== =============== =============== =========
This was working fine.
Then I needed to repeat this code (except for the first two lines) several
times, every time for a different value of le
I placed everything starting from lime 3 inside {}, made is a function and
called this function like that:
$chan = mysql_connect ($db_host, $username, $password);
mysql_select_db ($DB_name, $chan);
function write_table()
{
$resultid = mysql_query ("select name_ru, description_ru, retail, dealer
from lasershot WHERE le='1'", $chan);
.......
}
write_table();
Now I am getting this error:
Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource
in /files/home2/andrei/lasershot/pricelist_sql_a nsi_split.php on line 41
(line 41 is the former line 3:
$resultid = mysql_query ("select name_ru, description_ru, retail, dealer
from lasershot WHERE le='1'", $chan);
Why does the argument stopped being valid?
When I moved the first two lines inside the function, the line
$chan = mysql_connect ($db_host, $username, $password);
started generating error:
Warning: mysql_connect() : Can't connect to local MySQL server through socket
'/tmp/mysql.sock' (2) in
/files/home2/andrei/lasershot/pricelist_sql_a nsi_split.php on line 40
Does this mean that mysql_query() and mysql_connect() cannot be called from
within a function?
=============== =============== =============== =========
$chan = mysql_connect ($db_host, $username, $password);
mysql_select_db ($DB_name, $chan);
$resultid = mysql_query ("select name_ru, description_ru, retail, dealer
from lasershot WHERE le='1'", $chan);
........
=============== =============== =============== =========
This was working fine.
Then I needed to repeat this code (except for the first two lines) several
times, every time for a different value of le
I placed everything starting from lime 3 inside {}, made is a function and
called this function like that:
$chan = mysql_connect ($db_host, $username, $password);
mysql_select_db ($DB_name, $chan);
function write_table()
{
$resultid = mysql_query ("select name_ru, description_ru, retail, dealer
from lasershot WHERE le='1'", $chan);
.......
}
write_table();
Now I am getting this error:
Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource
in /files/home2/andrei/lasershot/pricelist_sql_a nsi_split.php on line 41
(line 41 is the former line 3:
$resultid = mysql_query ("select name_ru, description_ru, retail, dealer
from lasershot WHERE le='1'", $chan);
Why does the argument stopped being valid?
When I moved the first two lines inside the function, the line
$chan = mysql_connect ($db_host, $username, $password);
started generating error:
Warning: mysql_connect() : Can't connect to local MySQL server through socket
'/tmp/mysql.sock' (2) in
/files/home2/andrei/lasershot/pricelist_sql_a nsi_split.php on line 40
Does this mean that mysql_query() and mysql_connect() cannot be called from
within a function?
Comment