Database Query From Within A Class Function
My application is object orientated and each object requires a cooresponding "PageID" in the tables "Page" and "PageContent" as well as a few other necessary elements to display properly as a web page.
Some page elements are contained in their own tables, but are associated with the"Page" and "PageContent" tables by the "PageID" that cooresponds to the page the element should be displayed on.
I have written a script that allows me to create a new page by inserting data into fields on the "Page" and "PageContent" tables, but it only works as long as the "PageID" in each table is auto_incrementing in sinc.
I wanted include a method for members to sign-up for the site and I fould a script named "Authlib v1.94" that seems to work pretty well on its own. However, I hacked the code to redirect the data to an existing member table and cut out some of the validation. My intital tests on the hack have been satisfactory.
If any of you are familiar with the "Authlib v1.94" code you may be aware there's a file named backend.php included in the script. It is a class file that includes some pretty nice validation functions for dealing with registering new members, logins, etc.
The register function of the authlib class validates user input from the regestration form. If all the checks pass, it goes on to create a new entry in the "Member" table. (Keep in mind that I redirected the data to this table and hacked the code a bit.) The code looks something like this: PHP Code:
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Access Class Member Function Without Instantiating Class?
I need to access a class member function from outside the class, and hopefully without having to instantiate the class if possible? I have an HTML form <select> and each <option> item is being pulled from an array stored in a mysql db. But I'm doing this independently of the normal purpose of the class itself, I just want to use that member function.
Coding A Class' Function Outside A Class
I still haven't found if there is a way to write functions (methods) that belong to a class, outside of that. Maybe there is not, at least untill now.But I prefered to post a question here about that in case there is and someone knows.
Function Inside A Class Function Dont Pass Variables...
Im using xajax class, and i just made a custom class called mantenimientos that use objects of this xajax class. Something like this: class mantenimiento { public $titulo; public $ajax_sRequestURL; function __construct($titulo,$ajax_url){ $this->titulo = $titulo; $this->ajax_sRequestURL = $ajax_url; } function exec_ajax(){ //Here i can use $this with no problem $xajax = new xajax($this->ajax_sRequestURL); $xajax->registerFunction("call_fun"); //I have to do this to have acces to the class itself when im inside a function global $mant ; $mant = $this; function call_fun(){ //next line give me access to the mantenimiento class properties. //I havent found other way of doing it. global $mant; $objResponse = new xajaxResponse(); $objResponse->addAlert('XAJAX CALLED:'.$mant->titulo); return $objResponse->getXML(); } $xajax->processRequests(); } My problem is that $mant->titulo lost it value when i im inside the funciton, but only when that value comes from other var. for example: if i do this: $mant = new mantenimiento('This is the title','index.php'); or $titulo = 'This is the title' $mant = new mantenimiento($titulo,'index.php'); When i execute the xajax_call_fun, it shows an alert box with the text "XAJAX CALLED:This is the title" but if i do something like this: $titulo = gettitulo_from_database(); or $titulo = $_POST['titulo']; The alert box show the mensaje with out the value of the $mant->titulo Im getting crazy with this....!
Class + MySQL Query
For some reason the result keeps comming up null. All the echos are there to see if the values are there at certain points and ill take out once it works... The checkClockIn function is called from another file but I know its ok because $emp has a value so i know i declared the class in the other file correctly. Code:
Database Class Within A Other Class
I’m rewriting a script of mine into PHP5 OOP. Even tho I have some difficults finding a good way. I have a Class for database connections/functions (clsDB) and a Class for Statistics (clsStats) So my question is, what’s the best way to use the DB functions within the Stats class? Code:
Database Class
I just made a database class that connects to mysql and does query, connect and various other database operations. Now i made an instance of this class in my main page am able to use it without a problem. But now i am having trouble when i am trying to use this object when i open another page. I want to be able to use the same instance from the main page so i need some way of passing it from one page to another. I can probably get around this problem by just making another instance of this class and making another connection to the database, but i would like to do it without making multiple connections if i can. Any suggestions?
Abstracting A Database Class
I've been using PHP for a while and I'm hearing that I should look into using it OO. I'm looking into making changes to the program Camera Life (http://fdcl.sf.net). I want to abstract the connection to the database which is currently MYSQL and maybe implement another database, or just leave it open for addition. If I get lucky and get the hang of this, I'd also like to abstract calls to GD. So firstly, is there a good solution to this problem? I've seen many examples, but many of them are incomplete or simply academic. Also, will I lose any functionality by doing it this way? I am currently using a complicated SELECT statement with a CONCAT. Will this be possible with the abstracted class?
Database/SQL Abstraction Class
I am currently writing an application that I want to work on multiple database systems. However I am not sure what is the best way to abstract (factor out) the database code from my main application code. Currently I use ADOdbLite to abstract myself from the different db APIs used however this does not protect me from the different variants of SQL used. How would you suggest I do this. Some people have told me to write a DB class that contains all of the queries wrapped in functions, such as getUserInfo($userID). Does this seem like good design practice, and if so how much work would you suggest the functions/methods do, should they just run the query of return the result set or also process it into something like an array?
Class For Database Connection
Can anyone tell How to write class for database connection in PHP . Class must provide a general function for executing queries.
Using A Function Within A Class
I have written a class (and it works!). Now I want to tidy the code a bit by separating some subroutines and I get a "Fatal error: Call to undefined function:" e.g. class Fred{ function Fred(){ //constructor do_this(); } function do_this(){ blah blah } } Please can someone tell what I'm doing wrong? If I use function_exists(do_this) it returns false. I've tried putting the function as the first block in the class. I've tried calling it as a method e.g. $this->do_this(); PHP 4.3.9 on IIS (localhost)
Database Class: Closing Connection
I am just learning OOP in PHP and I decided making a DB class would be a good start for my first real type of OOP class. Everything is working fine but I am having problem's closing the connection. I was wondering if anyone can see what the problem might be if it is in the coding. database.class.php PHP Code:
Passing A Class To A Function...
if I have something like, (still using PHP <5) function c( &$obj_someclass ) { // do more work on it $obj_someclass->SomeFunction(); } function a() { $z = new CSomeClass // work on $z c( $z); } I get an error 'cause function c does not know that $obj_someclass is of type CSomeClass How could I do the above? or must I declare it global?
Output Class Function To $var
I am having a bit of a problem with my first class. In general there is a function named "table" in my class that I wish to retrieve a string of info from to be passed on to fasttemplate. PHP Code:
BUG: Referring To A Class Function
This is a "namespace" problem with "::". Is there an official place I can report php bugs? I'm new to PHP (and soon to be leaving it): class SomeClass { function dostuff($ar) { uasort($ar, 'SomeClass::somesort'); } function somesort($a,$b) {<-- never gets called echo "Yes I got called"; //<-- never happens if ($a[order] == $b[order]) { return 0;} if ($a[order] < $b[order]) { return -1;}; if ($a[order] > $b[order]) { return 1;}; } } SomeClass::dostuff($ar); //put whatever you want in the $ar array to test In the line "uasort($ar, 'SomeClass::somesort');", 'SomeClass::somesort' isn't recognized by PHP. I also tried just 'somesort', no go. I was trying to use a class as a substitute for PHP's lack of namespaces. (Which btw is the reason I'm bailing out of php.) Because of this bug I have to put my sorting funct into the global space, which is ridiculous.
Class Or Function For A Key Generator?
I need to be able to produce a string consisting of uppercase letters and numbers. I would also like it to produce e.g. a string of 6 characters all the time. A given number must allways result in same string such as "AE4YX8". Would also be nice if I could go from the string to the original number as well. Anyone with links to sites with example on how to do this?
Pass Var From One Function To Another In Class
Im getting a var sent to one function. Which I need to use in another function within a class. This is double right? The var can be seen in the first function under the name $num2,.. and then I try to use it again under the rows function,.. I will attempt to highlight this var in black... Code:
Using Class Inside A Function
I'm trying to utilize a class from inside a function. I've set an object of the class outside the function and inside the function, when outside did not work. The error for outside the function is "Fatal error: Call to a member function on a non-object in generate.php on line 103". The error for inside the function is: "Fatal error: Call to undefined function: query() in generate.php on line 100". I don't understand what is wrong. Can anyone help?
Assign Function To Class....
Is it possible to assign some functions to a of a class? class loginClass { function initialize() {$something} } function CheckLogin() { $something } $login = new loginClass(); $login->onLogin = CheckLogin(); $login->initialize(); where the CheckLogin function will only be run during the initialize of the class, not during loading of the whole document.
Simplifying Repeating Database Connections In A Class?
I wrote my first PHP class today. Yeah! But to get it to work, in each function within the class I have to repeat the database connection lines, and that just seems redundant; there has to be a better way that I'm just not bright enough to think of. (It's the first 3 lines of each of the two functions below. When I have it fully written, there will be about 10 similar functions, each repeating those three lines.) class e_test { function gettech() { include('../Connections/userDBconnect.php'); $db = mysql_select_db("printing", $connection) or $error .= "Could not select database1: " . mysql_error()."<p />"; $dbconn = $connection; // CREATE TECH ARRAY $sql_T = "SELECT email FROM tbl_users WHERE dept = Ƈ' AND active=Ƈ'"; $result_T = @mysql_query($sql_T, $dbconn) or $error .= "Could not query1: " . mysql_error()."<p />"; $count_T = mysql_num_rows($result_T) or $error .= "Could not select query2: " . mysql_error()."<p />"; $i_T = 0; while ($row_T = mysql_fetch_array($result_T)) { $email_T = $row_T[email]; $techs .= $email_T; $i_T++; if ($i_T < $count_T) { $techs .= ","; } } echo $error; return $techs; }
Creating A Search Class That Searches Any Database
I've been requested by a client to implement a search engine on it's website. I told him that he does not need it, but he thundered on and well...Who cares, he' s gonna pay for it. I've made search methods for other sites, but I would like to implement a portable one. A Search Class that could work for any DataBase and with ease of configuration. Maybe de constructor could receive a database name in which to search. And the function search, could receive an array of tables in which to search on and a string to search for on those tables. The question is...how would u implement the way that the class returns results? Nowadays any pro site has the MVC controller. That means that almost all tables in the database have its corresponding model. Table clientes correspond to the Client Model. How would you implement the results return?
Session Variable Within Class Function
Background info: the application I'm working on has register globals enabled. session_register is used to establish the session variable in every page (via included file). How do i access that session variable from within a class? I've been doing some reading and all I've determined is that using session variables within classes is tricky businesses.
Ob_start And A Callback Function In A Class?
i want to use a callback function for my ob_start inside of a class. but it wont work in any way. ob_start("bar") works fine if the function is not in a class. ob_start("$foo->bar") or ob_start("Foo::bar") doesnt. Is there a way to use a function inside of a class for a callback?
Join Function In A Class Template
Below are snippets from a routine that runs queries on the database, processes the information through a PHP class ("HtmlTemplateClass.php") and then outputs the applicable output on an HTML template ("TopNewsTemplateP1.php"). It all works except for the $Page->SetParameter ( "PUBLISHED_ARTICLES", join(" ", $NoArticles) ); part. The $Admin[] "join" function and the $Reporter[] "join" functions work fine. However, they are both arrays. The $NoArticles "join" function does not work. Obviously, the $NoArticles variable is not an array so I need to treat the $NoArticles variable different than the $Admin[] and $Reporter[] array variables. Can someone tell me how to write the snippet to replace the join("", $NoArticles) below? (Note: For some reason the "newline" backslash is not appearing before the "n"'s below on this posting.. ?) PHP Code:
How To Access A Function Of A Parent Class ?
if i access a function of a class, i do this : $x=new Class; $x->function(); how do access a function of a parent class ?..let's say, class "Class" has a parent class "Parent" and "Parent" has a function n(). how to access n() from Class above ?
Return A Variable From Class Function
I have been working on something that should be simple but I cannot figure out how to do it. Basically, I am working with a PHP class that handles MySQL queries. The code to call a query looks like looks like: $dbcn->db_qry("DELETE FROM contactus WHERE id='$id'","1"); This function is inside a class called db_connect. The function is function db_qry($qry, $type, $from="") { $this->dbQryResult = mysql_query($qry) or $this->goError($qry, mysql_error(), $type, $from); } As the function shows, if the query fails, it is directed to the goError() function where it prints an error message. The problem is that some instances, I want it to instead return a variable back out of the function. The variable holds some information so I can print out the error message later in the page. In this case, it should return a variable indicating whether the query succeeded. That variable will be used in the following part: Code:
Variable Class Function Names
I have a class that may have a lot of relationships and I would like to do something like this... public function getRelated<classname>(){ // Whatever logic } But I want <classname> to be variable...for example getRelatedBooks getRelatedArticles, each class has his own relationships. Can that be done?
Looking For Independent Database Class That Supports All Major Databases
I guess the title says all. I'm looking for independent database class that supports all major databases. I ran across this in the past, but now that I need it I can't find it. It is a class that allows a programmer to select which database the program will access. It is built so that a script can be portable without write to database functions.
Database Class Allowing Saving Data To (XML?) File
I'm looking for a PHP database class which allows database connections to mysql, AND (text/XML) files to store information. I'm looking to use the file storage in a small intranet usage of my programming, and the database (mysql) storage in an online (internet) site. If anyone knows of any open-source PHP code for this,
PHP5 Class - Call To Undefined Function Sum()
Dear All, I have problem with the class I use class in PHP5 like this: <? calss myPHP{ function sum($x,$y){ return $x+$y; } function all($a,$b,$str){ $total=sum($a,$b); return "$str=$total"; } } ?> the error have show : call to undefined function sum()
Use Function In Class W/ Custom Error Handling
I'm trying to set a function that is held within a class as the custom error handler using the set_error_handler(), which takes the string name of the custom error function as its argument. I fully understand this, however, how do you use a function that is declared within a class? PHP Code:
Splitting Class/function Declarations & Definitions
Is it possible to split-up a class declaration and its' functions definitions? By this I mean the same idea as in C++ with header and source files. Having to define my functions within its class declaration is clumsy and untidy, made worse by larger classes and functions. PHP Code:
Accessing Array Returned By Function From Class
I have a function in a class that returns an array of query results, but I can't for the life of me use the array results once retrieved from the class... here's the code I have so far: PHP Code:
PHP5.1.6: Class DateTime Not Found / Undefined Function Date_create
I am using PHP 5.1.6 on RHEL5 server (is default installation of PHP). When using DateTime I get a fatal error: Class DateTime not found, the same with the function date_create: call to undefined function. According to the PHP manual DateTime and date_create are available from PHP version 5.1.0. The development machine uses PHP 5.2.1 (everything works fine), but...
Getting Database Name For A Given Query
In PHP you can retrieve the table.column name of a MySQL query doing something like this: $result = mysql_query($query, $dbConnection); $resultArray = mysql_fetch_row($result); $i = 0; foreach ($resultArray as $data) { $tableName = mysql_field_table($result, $i); $fieldName = mysql_field_name($result, $i); $returnVal["$tableName.$fieldName"] = $data; $i += 1; } The problem is that I am selecting across databases and it is conceivable that two tables will have the same name. How do I get the Database Name for a given field? I would want something like this: foreach ($resultArray as $data) { $dbName = mysql_field_db($result, $i); $tableName = mysql_field_table($result, $i); $fieldName = mysql_field_name($result, $i); $returnVal["$dbName.$tableName.$fieldName"] = $data; $i += 1; }
Logical Database Query
I currently have 2 tables in my database. One called "members" and another called "phpbb_users" (which is the user's table in my forum) Basically I want to get all the results from my members tables and then automatically insert the values into the phpbb_users table. I have the following code below which I am trying but doesn't work. Can anyone offer a little support on this? Code:
How To Use My Md5 Function In A Query?
The little problem I have is its not returning the password only the hash form of it. Can someone show me where to insert the md5 function. I tried everywhere I can think of.. Code:
Daily Automated Query Of Database
I would like to run a script on a daily basis that queries a DATE field in one of my tables. I want to do this to establish the age of my table entry by comparing with the current date. Could someone please give me a few pointers on how to get started in solving this. I just read somewhere about cron jobs but I've never used them? I'm running Apache (2.0.54) on Win XP Prof with MySQL (4.1.10) and PHP (4.3.10). All on a local machine so I can set all appropiate permissions.
Sorting Database Query Results
I want to know if it is possible to sort query results so that the records with a value in a certain field is displayed first and the records with the field empty thereafter.
2 Drop Down List Where Need Query Database
there is drop down list box linked to the database where it displays the state of a country and once the user clicks on the particular state, there purpose to be radio button displaying the locations available of that state, the location displayed in radio buttons are from the database. currently the source code i'm using is (which uses a submit button to query the database but i does not want the submit button it purpose to work using Code:
Database Query Or File Read
Specifically, is it faster to store template source in a database (MySQL) and run a query or in a file and use the file functions to get the contents? Advantages/Disadvantages of both other than the speed difference?
No Database Query Is Allowed Yet Value Is Still Returned
I am developing. One of types of users we allow is "justTestingTheSite", a type of user I developed to give demo's to prospective clients. The purpose of this level of security is to let someone log in and see everything as if they were root, and yet not be able to update or delete anything, as they have no real priveledges at all. I just logged in as root and created such an account, then I log out and logged back in using the new account. I tried to edit the weblog on the front page of the site. Everything worked as it should of: I was able to get to the screen, edit it, and hit submit, and then, because of my low security rating, the software did not change the values. Perfect. But the results message said "You've just updated 26 items." I was expecting it to say "You've just updated 0 items." 26 just happens to be the number of entries on the weblog which is the front page of the site. For the life of me, I can not figure out how the software got the number 26. More so, the message seems to be incorrect, none of the 26 items seems to have been updated. function standardUpdate($functionForEditing) { global $users; $users->check(); .....
Using Session Data To Query A Database
Basically the title is the general idea of what i'm trying to do, a user logs in, great, his login id is stored (it is also his number on a seperate database) in a session variable. Now that session variable needs to be queried to another database (with all of that users information) to get all of the information on that user back to the original server (not the first database, the first database just has user number, id, and a password field). So I have a question, and if you have answers great! or if you know of the thread that they are on that would also help because i've been searching and haven't found anything yet. 1. How can I query a session variable in a sql statement, do I just put select * from users where '.$_SESSION['mysessionname'].' = usernumber ?
Convert Date From A Database Query
I have a simple database for events. I have a column named "date" that I would like to display as "March 8, 2007" on the webpage. What do I need to add to change the date format? Here is my php code:
Query: Mail() Function
I'm having some trouble trying to send mail out when I retrieve the emails from a DB. I really don't know whats going on, but I have tested this on 'normal' email and this works fine but when it comes to a email from a DB it doesn't work. PHP Code:
|