Here is my problem, i have a class with a ave method, i want to pass a Mysql DB link to it, so i create a new object from the class, and call the saveProperty method, and in my main file i created a MySQL connection and saved the link in a var called $db so when i call the method it's link this: saveProperty($db).
but insted of saving the data i get an error:
Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in C:\wamp\www\aqaria\classes\property.php on line 75
Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in C:\wamp\www\aqaria\classes\property.php on line 99
which means that i didn't pass the link right? but how?
here is some of my code:
<?php
class test
{
function saveProperty($db)
{
$sql = "<<query goes here>>"
mysql_query($sql,$db);
if(mysql_affected_rows()>0)
echo "<h3>Data was saved</h3>";
else
echo "<h3>Error saving data</h3>";
}
}
here is the calling code:
$db = mysql_connect('localhost','root','');
mysql_select_db("aqaria",$db);
$property = new Property();
$property->saveProperty($db);
although it would work if i added the gloabl keyword to method of the class i was wondering if i can PASS the link to the database connection?