Empty QUERY and cleared variables in MYSQL
Posted 04 September 2006 - 04:26 AM
Im new to PHP - so still getting a grip on hopefully whats obvious to someone,
although having read the manual - not obvious to me.
I am modifying an existing script and it just dont seem to work on my machine.
a WAMP server.
Environment as follows:
***** Test.php ***
// have code that sets up a variable called $statment.
$statment = "select * from debtors"
$res = sql($statment)
**** sqlfunctions.php ****
echo $statment // gives me select * from debtors
// connect to DB
echo "error" . mysql_error();
echo $statment // gives me nothing - variable contents seemed to have been cleared??
// when i try to use $statment in actual qry - i get "empty qry" error.
So - any obvious mistakes here??
Thing that annoys me is that im told this style of coding works on someones production
Posted 04 September 2006 - 10:07 AM
Both extensions have their own set of mysql functions. For exmaple the mysql improved extension has these functions:
Notice the i after mysql. The mysqli extension will only work with the functions prefixed withg mysqli. It wont work with functions prefixed with mysql. In order to use the functions prefixed with mysql you'll need to use the normal mysql extensin (php_mysql.dll)
Posted 05 September 2006 - 02:02 AM
If i take the php mysql_* code out of the Included PHP file and
out of the function, and just use it directlyas inline code, it all works fine.
That leads me to believe the actual syntax of the Mysql code is fine.
It something to do with the Include process, the Function process, or
maybe .ini file or some combination.
Just dont know?
Any more ideas?
Is what im doing - SQL code within user function within Include file - all OK
Posted 05 September 2006 - 12:10 PM
Is the following code, whats exactly in test.php
include ("./sqlfunctions.php") // have code that sets up a variable called $statment. $statment = "select * from debtors" $res = sql($statment)
If it is it should be this:
include ("./sqlfunctions.php"); // missing a ; // have code that sets up a variable called $statment. $statment = "select * from debtors"; // missing a ; $res = sql($statment); // misssing a ;
You have forgotten to add the semi-colon on the end of each line. You must make sure every line has a semi-colon at the end of it, unless you are defining a function, using an if statement/while loop etc.
Posted 06 September 2006 - 12:49 AM
The code i was giving was an example.
display_errors = On
error_reporting = E_ALL $ ~E_NOTICE
2. more Code
** test.php **
include ("./sqlfunctions.php"); // contains user function called sql, for mysql functions
$statment = "select * from debtors where Ourref=$selected_id";
$res = sql($statment);
$row = mysql_fetch_array($res);
** sqlfunctions.php **
echo $statment; // displays correct contents of $statment eg: "select * from .... " etc.
echo Stylesheet() . "\n\n<div class=Error>";
echo $Translation["error:"] . mysql_error();
echo $statment; // display empty (or null?) contents of $statment eg: "".
The first echo displays the correct contents.
The second echo shows nothing.
The sql statment mysql_connect runs and connects.
failure code isnt actioned, therefore no other functions or actions are taken before the
second echo $statment;
To me (limited expertise excepted), The $statment variable seems to be reset
by the mysql_connect function call.
I've even used other variable names eg:$statmentxc and get the same result.
This is sending me bonkers!!
There has to be a simple solution to this.
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users