Hey all, I'd like to consider myself pretty decent at PHP, but I've only recently started to move my projects into the realm of the object-oriented. Until now I've only used OO with Java and a bit of C++. Essentially I'm trying to encapsulate a database using objects. The issues are primarily with managing the complexity of the data model.
I have a database table for users, let's call it users, and this table has fields along the lines of userid and displayname.
I've created a User class which instantiates to a User object. Each of the fields (a/k/a columns) from the database is a so-called Field object. (So now a User object is a collection of Field objects). Internally, there is just an array of Field objects. To be able to display these Fields in different ways in the output, I've abstracted the display of the Field object into a FieldPrototype Object, which also contains information about the Field's data type (e.g. integer).
So User is a collection of Fields, which is a FieldPrototype and a value which is accessed and according to the FieldPrototype.
I anticipate that there may be up to several hundred of these objects instantiated at a time (and efficiency is a concern), so I've made the FieldPrototypes static members of the User class.
Thus, if there are 100 User objects instantiated, each of them only carries around a value and an address of a FieldPrototype that is used to display and describe the Field.
My question, then is how logically this is laid out and if the added burdens of creating static objects as descriptors of instantiated objects is worth the performance increase (or really if there even is a performance increase).
I've put some time into this code already, visible at this page (user: lj, pass: lj). If it helps... Most of what I'm talking about takes place in the User.php file.
This promises to be a fairly large project, and I'd like some experienced input before I go off and implement a system on fundmantally-flawed ideas.
Also, anyone have any good resources (or book suggestions) for this sort of stuff with PHP? That is, Object Oriented + Database on a relatively large scale?
I have 3 development environments: Workstation at work, my laptop, and the workstation at home... my code is moved between all these machines with svn and it works perfectly, so it makes me wish I could do the same with development schema's or whole Databases.
Is there anything like svn for Databases? I know about and use replication, but that's a tad too much just to allow me to work from a coffee shop or catch up on some work on the weekends. Right now I have a fetchSchema.bat file for my windows machines that grabs the current schema/data from the dev server using mysqldump.
Which reminds me of another question for another post.
I'm sorry to disturb, I'm new in php and I have a trouble with this code:
It has to extract a row from a mysql database and make a html select of the value id_persona displaying also the value of the other fields (Nome, Cognome, Organizzazione) but it don't works properly. Choices on select are displayed like in the attached photo instead with the correct data .
Ok, so I have a fully UTF-8 MySQL database with a fully UTF-8 table. I have a php page which has "" at the top of the html section and "mysql_set_charset("utf8");" after my connection (it's php 2.2.3, so that's more or less the same as "mysql_query("SET NAMES 'utf8'");). I have all my php.ini mbstring stuff configured for utf-8:
mbstring.language = Neutral mbstring.internal_encoding = UTF-8 mbstring.http_input = auto mbstring.encoding_translation = On mbstring.detect_order = auto
and for what it's worth, echo mb_internal_encoding(); reports "UTF-8".
when I run a query that pulls out (in this case, Japanese, but say any) UTF8 data, it displays properly in MySQL Query Browser. With php in the above context however, it does not. Instead, it prints a ? corresponding to each character. When I use mb_detect_encoding(); on each such string, it tells me they are encoded as ASCII. The nearest I can tell is that somewhere between using mysql_query() and mysql_fetch_row(), things got messed up. Is this a bug? Is there something I'm missing? Any clues? Help!
I was presented with a laptop that had been partitioned (supposedly by the manufacturer) in a very odd manner: 15GB C drive, 54GB D drive and the remainder of the 80GB drive as unpartitioned space. I needed to install a piece of software that has a minimum requirement of 20GB. This requirement included the estimated database size that would, ultimately, be user-generated. Obviously, 20GB is not available on a 15GB partition. So, I used Acronis to image all the partitions on the drive and then I re-partioned the drive to a single volume. When I restore the image from the original C partition to the new C partition everything goes fine. I set the new partition to be the active partition (e.g. boot-able) and all the data appears to get restored fine. Except for one issue, after re-booting, it will not boot. It claims it cannot boot the to partition and that my hardware configuration is wrong. After trying this a few time with various different settings all recieving the same result I thought about doing a "dirty" restore. So I did. I installed a clean version of windows (XP Pro) to the disk and then I did a restore over the windows directory. At first glimpse, this worked.... but it has different issues. All the data and settings seemed to carry over but my wireless settings are not correct (in fact the services associated with them are not even running) and a program that uses audio will also not run. I am also having issues with the user-content synchronization with the server (even on the wired network, which works even though I cannot get to the settings).
I know I should have written down the exact boot error message, but I figured I would be able to solve the issue....
Anyone have any thoughts? I really do not want to have to manually restore all the files and install all the programs from scratch unless I absolutely have to.
At my place of employment, we have a web form that will send an e-mail to our IT helpdesk person so they know that a work order has been placed. Currently, there is no reliable automatic way to send a confirmation e-mail saying the work request has been received. Despite the fact that we specifically ask the person requesting the work to enter their e-mail address, they usually don't, or just put their computer username because they don't know the difference (Asking people to read instructions? Shocking!)
I had this idea today that perhaps our Exchange server could be queried to pull the names/usernames of all the people in our company so they could choose their name from a list, rather than relying on them to actually read the instructions and enter their e-mail.
Another option would be to just dump everyone's name and e-mail addresses into a small database and query that. Unfortunately, this adds extra steps for our helpdesk people to follow when creating new users, and requires them to have access to our web server, which we'd rather not give.
This idea literally came to me like 5 minutes ago, so I'm coming to you, oh Great and Wonderful LJ Community, to ask if this sort of thing is doable, and if it is, what kinds of stuff would I need to use with PHP to get it to work?
I should note that our Exchange server is hosted externally, as I'm sure that sort of information makes a difference.
HSQLDB is an unique high performing, high quality Java based relational database which can be very easily extended with simple Java static functions. Here we will see how you can easily extend the database capability with a real-life example.
I wanted to do a case-insensitive LIKE comparison, specifically get rows where the column data contains the [...]
I have a chronic problem with a fanfiction archive script I made. Since I've put it online, I hit max_user_connections in MySql very often, and my host is losing patience. The script opens a mySql connection (originally a normal one, now a permanent one by my host's suggestion) on loading and should use it for all the mysql calls forward. The archive is famous in the fandom and gets a lot of hits, but this shouldn't happen. I've tried to reduce the mysql calls at minimum, but I only get a few days reprieve. This is the code I use:
In db_layer.php:
function db_connect ($db_host, $db_user, $db_password, $db_database, $use_persistent = 0) {
Normally we need fake id’s when we are developing or testing any application with user authentication & entitlement. Fake ids are required to populate the database for testing. I wouldn’t recommend that you use them to fill in the website registration forms which asks you for personal information, no Sir. Here is how you [...]
I previously discussed how to extend HSQLDB relational database with simple Java functions. The example there actually implements case insensitive like query functionality for HSQLDB. Read the article to get an understanding of how to write such custom functions and how to use them. Then read below to find a solution for performing space crunched [...]
Another dumb question. At least I give you guys the easy ones, right? SQL2K5, latest SP, etc etc.
I'm trying to pull everything to the right of a comma in a cell. To spare me having to upload data, I've recreated it in a quick procedure using a variable to store the location of one of the cells in the table:
My problem seems to stem from SQL treating the LEN() and RIGHT() commands differently, as far as I can tell-- LEN(@Author) returns 16, which is the actual length of the data in the field, but when I use RIGHT(), the padding is included, and consequently I get a field full of spaces. I've attempted every combination of LTRIM(), RTRIM() and @Author I can think of, and I still end up with a field full of spaces as a result set. When I declare @Author as char(16), I get the proper results, but in the table itself, there's no way to do that (multiple author names are, for obvious reasons, variable in length) short of using a cursor and going row by row, and I'd rather not do that (I'm not fond of cursors in the first place, and this is a relatively big table for a scan-and-modify routine, so I may run into time concerns).
I vaguely recall there being some variation on the SPLIT() command in T-SQL, but the sieve that is my brain has forgotten what it's called, and searching on "split" in books online is coming up with squadoosh. Anyone know what it is I'm forgetting? (And whether it's possible to use the command to update two to four colums in the database at once?)
HSQLDB is a high performance RDBMS written in pure Java. It can be used as a in-memory database or regular file based database. It can also create a read-only database out of any CSV files. HSQLDB is the database used with OpenOffice. The steps to quickly and safely backup HSQLDB Database are:
Run the SQL command [...]
This one's got me at the end of my rope, and none of the answers I'm finding searching in the many places I've searched have given me any help, so I'll ask you guys.
First off: I am brand new (as in a couple of weeks) to MySQL, after moving to Ubuntu (Feisty) at home. (Goodbye Microsoft.) I'm a SQL Server DBA/DWA/Database Developer/jack-of-all-trades at work, so I do have some DB experience, just not with MySQL.
Anyway, I've created a schema and the tables in it. Now I'm trying to relate those tables. All use the InnoDB engine.* The guinea pigs I'm using are the BOOK and AUTHOR tables, and I'm trying to relate the ID field in AUTHOR to the AUTHORID field in BOOK. (And, yes, I've tried changing the name of ID to AUTHORID with no success.) Both are type INT. ID/AUTHORID is an ident-seeded primary key. AUTHORID in the BOOK table is a foreign key. Or it's supposed to be, but when I try to relate them, I get the infamous error 1005 (can't create table './directory/filename.frm'). I've found extensive discussion on this at ubuntuforums, forums.mysql.com, and a number of blogs, and have checked everything I've found, modified everything I can, and I still get the error. Basically, if you search on "error 1005" on google and check the first 150 non-repeating pages that come up, I've tried/checked everything that comes up to no avail. I'm at a loss for what do do next, and hoping someone has some ideas.
Also, I tried running a MySQL instance on my XP machine at work, created the exact same tables the exact same way, and tried the relation. It worked on the first try without a hitch.
If anyone's got some help, I'd be truly grateful. Thanks. If more info is needed, I'll report back tonight when I'm actually sitting at my Ubuntu machine.
* As a side note, for philosophical purposes only: why are there so many available engines that don't support foreign keys? Do that many people create non-relational databases? Just wondering.
Database giant Oracle is delivering an update to its Java-based software development tools, the latest maneuver in the company's drive to grab more of the Java server software market. The company on Tuesday said JDeveloper 10g, its program for building Web applications, is available for $995 per developer. As part...
A few points to ponder ahead of the weekend...Why is my information always in the other database?When folks call customer service, some see incompetence. Others see red. I see data silos.This week I've called Verizon and Comcast about billing errors and been transferred repeatedly and also realized Yahoo thinks I...
My Google-fu is mostly failing me on this one. I need to provide a PDF for download, payment via PayPal. I'd very much prefer that the payment automatically validate and set up a username/password for downloading, so I'm looking for something more than a simple PayPal button.
It's just one PDF, so the usual shopping carts I've used (like osCommerce) are really overkill. I found and tried ipnDownload, but so far I can't make it function - it'll add items to the database, but when I send and it processes payments, it doesn't produce an email to the purchaser, add them as users, or record the transaction, so there's no download possible. I'm attempting to sort through the code and figure out what's going wrong, but it's taking a very long time.
Any suggestions for other similar snippet programs or experience with the same error in this one greatly appreciated.
One of the main challenges of managing multiple dedicated web / database servers is the ability to centrally monitor and manage them, automate tasks which requires out-of-band access like rebooting the server or find out if the server is dying and arrange for replacement ahead of time etc. Unless you are a very big web [...]
Is it possible to create a search function without using database?
If I design a site that's purely HTML, can I add a search function? There will many products on the page, and I want the user have the ability to search item name and list the page.
I wish I know MySQL and write backend. This is hard for me, probably will rely on frontpage extension.