PHP / MySql Function call problem

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
ierpe
Forum Newbie
Posts: 2
Joined: Tue Sep 23, 2008 7:29 am

PHP / MySql Function call problem

Post by ierpe »

I wrote a class Database, defining the methods connect(), close($con), select_gen($query,$con), update_gen($query,$con).

The method select_gen is just calling the mysql_query method:

Code: Select all

 
function select_gen($req,$con){
  $reponse=mysql_query($req,$con)
or die("Query Error");
  return $response;
}
 
Now, in one of my php pages, its working if i call the mysql_query method, but not if I call the method for my object database...

Code: Select all

 
//Creating the object and the connection
       $db = new Database();
       $con = $db->connect();
//formatting the query
    $string = mysql_real_escape_string($string);
    $sql = "SELECT * FROM sg_content as t1 WHERE t1.content_name LIKE '%".$string."%' OR t1.content_des LIKE '%".$string."%' ORDER BY t1.content_id";
 
[b]/* This works! */[/b]
    $result = mysql_query($sql,$con);
[b]/* This doesnt throw an error but return an empty result */[/b]
    $result = $db->select_gen($sql,$con);
 
    $db->close($con);
 

Why? I dont understand... im just passing a variable in parameter to do the exact same treatment... please help me!
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Re: PHP / MySql Function call problem

Post by Maugrim_The_Reaper »

Typo in your function ;)

$reponse should be $response.
ierpe
Forum Newbie
Posts: 2
Joined: Tue Sep 23, 2008 7:29 am

Re: PHP / MySql Function call problem

Post by ierpe »

omg thx...
Post Reply