php - pass MySQL link to a class method -
Here's my problem, I have a class with Away method, I want to pass it with mysql db link, So I create a new object from the class, and call the saveProperty method, and in my main file I have created a MySQL connection and saved it in a var called $ db, when I call the method it is from this link Is: saveProperty ($ db)
But to save the data, I get an error:
Warning: mysql_select_db (): Distributed logic is not a valid MySQL-link resource C: \ wamp \ www \ < / P>
WARNING: mysql_query (): The supply logic is not a valid MySQL-link resource C: \ wamp \ www \ aqaria \ classes \ property.php on line 99
Which means that I did not correct the link?
& lt ;? Php class test {function saveProperty ($ db) {$ sql = "& lt;
Here is the calling code:
$ db = mysql_connect ('localhost', 'root', ''); Mysql_select_db ("aqaria", $ databases); $ Property = new property (); $ Property- & gt; SaveProperty ($ Database); Although this would work if I had added the globile keyword to the class method, then I was wondering if I could pass the database connection link?
Have you tried with a reference?
In addition to $ db you can use mysql_affected_rows ()
function property (& amp; $ db) {$ sql = "& Lt; & lt; the query goes here & gt; & gt; " Mysql_query ($ SQL, $ Database); If (mysql_affected_rows ($ db)> 0) echo " data was saved "; Else Echo "& lt; h3 & gt; Error saving data & lt; / h3 & gt;"; }
Comments
Post a Comment