Subject:*
<
Name/Email:*
<
Message Icon:*
<
Select*
<
Message:*
<



Click the Preview to see the content in action.
Options:*
<
Confirmation Code*
<
8 - 2 = ?  
Input the result from the expression
Maximum attempts you can try: 10
*
<
     
query($sql); [/code] An insert would be done like: [code] $sql = 'INSERT INTO table (LastName, FirstName) VALUES ('McBeth', 'Lady' )"; $result = $testDB->query($sql); [/code] And so on. We are using the same code along the way and it is relatively simple to inject code into this if you don't use some sort of sanitizer. Xoops has all sorts of sanitizers throughout the code but on occasion something slips through. Not to mention the times you might not quite have your code written 100% right. I am looking at building methods that would allow the same functionality we have now but will make calling the queries simpler, allow us to make use of features of the different databases transparently and should be a lot more secure since we would be using prepared statements. The idea is that instead of sending the actual sql query to our code we want to send JSON style data to the methods and it will go from there. Why JSON? JSON is a common structure used throughout web design and works well for us here. I am using the "PDO 4 you" class for a basis for most of this code although it is modified anywhere it is used. A simple example would be to look at a normal delete query. Normally we might call a delete similar to the ones above. [code] $sql = 'DELETE FROM TABLE WHERE FirstName='Mickey' AND LastName='Mouse'"; $result = $testDB->query($sql); [/code] This is simple if we only want to delete one entry but if we wanted to delete a series of records we would have to repeat our setup of the query then call it over and over again. And check it each time to make sure it worked. With this "new" method we call the same routine differently. [code] $sql = ' { query : [ { table: "TABLE" , whereAnd: { FirstName: 'Mickey', LastName: 'Mouse' } } ] } '; $result=$testDB->delete($sql); [/code] This may seem a bit of work for something simple but if you want to do more than one deletion you could do something like this: [code] $sql = ' { query : [ { table: "users" , where: { id: 2 } },{ table: "users" , where: { id: 5 } },{ table: "users" , where: { id: 10 } },{ table: "books" , where: { id: 10 } } ] } '; $result=$testDB->delete($sql); [/code] This would delete 4 separate records in two different databases securely and simply. This is what I am working on now... It really makes a difference for select queries as well. (Note you need to count your own rows with PDO. There is no rowCount outside of MySQL normally and PDO programmers talk about it is better to count your own rows even with MySQL and MySQLi connectors because it is not accurate in ALL cases.) So currently you might use the following code to read in data and get the number of rows: [code] $sql = 'SELECT * FROM table ORDER BY T_id'; $result = $testDB->query($sql); if (!error()) $rowCount=0; while ($row = $testDB->fetchRow($result)) { $resultArray[]=$row; $rowCount++; } [/code] New method: [code] $sql = ' { query : [ { table: "table" , column: "*", order: "T_id" } ] } '; $result = $testDB->select($sql); [/code] The results will be returned in an associative array called $result. After this is done our row count will be available as: [code] $rowNumber = $testDB->rowCount; [/code] This is only an example and may not be exact. But this is the idea behind the new "proposed" PDO based code I am working on. The $sql query section will be setup a little different but I have to play around with it a little until I get what I want. Instead of "query" it may state what it is actually doing such as delete, insert, select etc... This makes more sense when we look at transactions... It may also allow me to simplify the code too and allow for one "query" command using the json style to accomplish everything instead of the current structure based on the PDO4You class that requires 8 separate methods calling 2 other methods. [/quote]" />

Re: Making a PDO "plugin" for 2.5.5 to potentially include in 2.6
by redheadedrod on 2013/8/17 12:50:24

I have some good news and some "bad" news....

The "bad" news is my work is dead on the PDO connector..
I will finish up the current connector I was working on and release it with the new MySQLi connector. There will be no new functionality added to this connector but since it is already pretty much finished it might as well be released after I finish some work on it. The proposed code I was working on will be removed so it is just another version of the current MySQL connector.

The good news is my experience gained from working on this connector will likely be included in 2.6 for a new much better database structure. More on this when complete. Further work on the PDO and MySQLi connector for 2.5 are not likely until the work I am doing now is complete.

Re: Making a PDO "plugin" for 2.5.5 to potentially include in 2.6
by redheadedrod on 2013/5/22 9:12:07

Today I am going to look extensively at the threads about things to add to the PDO connector I have been doing. I will be posting about the items I have working and the items I have found to add. My goal is to have a long programming session this weekend to accomplish finishing this connector. I will also take an extensive look through the 2.6 database connector to make sure this is primed to work with 2.6 with minimal modification. I am mentioning this now because I will try to post my "todo" list later today in hopes anything else that should be added can be mentioned so I can try to finish this up and provide it as a complete Alpha test connector in the next couple of days. Hopefully a Core developer can look through it and make any changes necessary and include it for the next alpha version of 2.6.

As I already mentioned, the skeleton is working great. I have to add the transaction stuff, the batch stuff and the actual execution of the SQL code. I am not really sure how the error logging system works in the core system but I am trying to duplicate it in the connector. Since prepared statements are cleansed before being performed I will be trying to use them in all cases for this class. I had to make an SQL class and include it in the database class to perform the chained methods.

At this time changes to Criteria are outside of the intended scope of this project but once I have this ready to be tested I could look into it more.
Re: Making a PDO "plugin" for 2.5.5 to potentially include in 2.6
by redheadedrod on 2013/5/4 19:59:06

Are you talking about in my PDO code or in the core code? I haven't looked very deep into the 2.6 connector yet to see what all has been changed or added. When I started this PDO connector 2.6 was pre-alpha 1 and I had not seen the connector. The ONLY thing I have added from the 2.6 connector at this point is the visibility keywords.

As of this writing I am DONE with my classes other than 2 final exams and 1 final project. My final project is on Neural networks so should be interesting and hopefully will be done today. I expect to get back to this connector as it looks now within the week depending on how much "wind down" time I need from this hectic semester. My finals are on Monday and Tuesday and my final project is due on Thursday but going to try and finish it today and tomorrow.





Re: Making a PDO "plugin" for 2.5.5 to potentially include in 2.6
by irmtfan on 2013/5/3 2:40:50

Quote:

it would be nice to have Criteria being able to create other type of queries besides SELECT, like INSERT, UPDATE and DELETE.

Now we have facilities for DELETE, UPDATE, INSERT in class/model
but they are general usage. (search for them and you will find)
After more investigation I think general usage is good and enough. ( but we can add some little and enhance it)
If someone like me want especial queries he can use $db but without hard-coded table.
eg in the current system you should use your object handler extended from XoopsPersistableObjectHandler:
le="color: #000000"><?php $sql = ... $result = $this->db->query($sql, $limit, $start);

so the above will be executed on my object table.
Re: Making a PDO "plugin" for 2.5.5 to potentially include in 2.6
by redheadedrod on 2013/5/1 19:21:32

I will look at it when I am done with the connector.

Like I said, the current criteria configuration looked like it would work well for the where clause but I didn't see where it was useful for anything else.

I will start a new thread for that when I get to it. Since it is more or a less an extension of the database connector I will look at this before I move on to the install script but after I have the main connector coded.

Who's Online

189 user(s) are online (137 user(s) are browsing Support Forums)


Members: 0


Guests: 189


more...

Donat-O-Meter

Stats
Goal: $15.00
Due Date: Jul 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $15.00
Make donations with PayPal!

Latest GitHub Commits