I have created a class that has two functions that deal with the connection with the database and to create a search Calling each other is my code, but it gives me an error ... there is something wrong with calling the function. Can somebody help me out?
class dB {public function connect () {session_start (); Include_once ('libs / Smarty.class.php'); $ Smarty = New Smarter (); $ Smarty- & gt; SetTemplateDir ('templates /'); $ Smarty- & gt; SetCompileDir ('templates_c /'); $ Smarty- & gt; SetConfigDir ('Configuration /'); $ Smarty- & gt; SetCacheDir ('cache /'); $ Host = "Localhost"; $ User = "root"; $ Pass = "pass"; $ Tablename = "table"; Return $ connect = mysql_connect ($ host, $ user, $ pass); Mysql_select_db ($ tablename, $ connect) or die (mysql_error ()); } Public function do_query ($ query) {echo db :: connect (); If (mysql_query ($ query, db :: connect ()) {$ message = "Annuncio inserito correttamente !!"; $ Message echo; } And {$ message = "Error in inserting data in DB:"; Echo $ message mysql_error (); }} }
Connect your return $ .. But you may want to return mysql_select_db $ connect = mysql_connect ($ host, $ user, $ pass); Return mysql_select_db ($ tablename, $ connect) or die (mysql_error ()); Edit: I was answering "something is wrong ..." because it was a clear mistake that the final statement is not executed.
But if you want to use Connect, you need to return it!
$ connect = mysql_connect ($ host, $ user, $ pass); Mysql_select_db ($ tablename, $ connect) or die (mysql_error ()); Return $ connect;
No comments:
Post a Comment