Code

Discussion on PDOModel - Database abstraction and helper PHP class

Discussion on PDOModel - Database abstraction and helper PHP class

Cart 247 sales

ddeveloper supports this item

Supported

125 comments found.

The documentation refers to fetchAll() in the introduction. When I run that example the error message back from PHP is “PHP Fatal error: Call to a member function fetchAll() on a non-object ” even though inserting an echo before the fetchAll() confirms 1 record found. Grepping the supplied code returns no occurrence of fetchAll() function except in the documentation introduction example. Need more info please? The code sample taken from the documentation introduction with echos added is… $DBLINK->where(“PRODID” , $zpid ); $result = $DBLINK->select(“wlxprod”); $ztest=$DBLINK->totalRows; /* the # of inv items in db .. 0 if none found … increment counter and put odd string in the html for manual edit/ echo $ztest; / returns a 1 which is the correct number of items */ while($row = $result->fetchAll()) { echo $row[‘PRODID’]; echo $row[‘PRICE1’]; }

Hi

You don’t need to call fetchall function. It returns data in format of array. You can loop through the array data using the foreach function.

Thanks

The documentation refers to fetchAll() in the introduction. When I run that example the error message back from PHP is “PHP Fatal error: Call to a member function fetchAll() on a non-object ” even though inserting an echo before the fetchAll() confirms 1 record found. Grepping the supplied code returns no occurrence of fetchAll() function except in the documentation introduction example. Need more info please?

The code sample taken from the documentation introduction with echos added is… $DBLINK->where(“PRODID” , $zpid ); $result = $DBLINK->select(“wlxprod”); $ztest=$DBLINK->totalRows; // the # of inv items in db .. 0 if none found ... increment counter and put odd string in the html for manual edit echo $ztest; // returns a 1 which is the correct number of items while($row = $result->fetchAll()) { echo $row[‘PRODID’]; echo $row[‘PRICE1’]; }

Hi

I have replied to your same question in other thread. Thanks

Went to use the INSERT functionality to update product and price listings however could not find syntax for equivalent of INSERT …. ON DUPLICATE KEY UPDATE price… Which demo or file can syntax be seen?

Hi

You need to use executeQuery function for this operation.

Thanks

rowsChanged always return 0 when doing a batch update.

Hi

For both point, I will check once again and send you updated file if required. Thanks.

Any news regarding the rowsChanged issue?

Hi

We have rechecked it. The suggestion given by us is working fine. I have tried to update 4 rows and it has shown 4 rows changed result. Please make sure to change following code in updatebatch function. $this->rowsChanged += $stmt->rowCount();

In case of still issue, let me know. I will resend you complete file. Thanks

How do I perform a Update if Exist, Else Insert

Hi,

You need to use executeQuery function for this. Thanks

Hello, i have a problem executing QUERY I do the following query :

$query1 =”CREATE TEMPORARY TABLE tmptable_1 SELECT * FROM operativo_movimenti_magazzino WHERE id = 16”;

$pdomodel->executeQuery($query1);

(the query works nornally if executed throught myphpadmin or similar program)

i get result error code : 16Array ( [0] => SQLSTATE[HY000]: General error )

please help Best regards

Hi,

I have just tried to run similar query in the demo database and it worked. There is “16” in message, have you done any echo or changes in the code? I hope you have done required connection settings.

Try below format also. $result = $pdomodel->executeQuery("CREATE TEMPORARY TABLE tmptable_1 SELECT * FROM operativo_movimenti_magazzino WHERE id = ?", array(16)); Thanks

I don’t get any results when I run:

$result = $pdomodel->select(“nnj_members”);

I just get a blank page.

Hi

have you created the object of pdomodel and “nnj_members” table exists? please enable error reporting also to see actual issue. In case of still issue, you can contact me.

Thanks

Greetings,

I absolutely love your PDOModel product (although I have previously purchased PDO Crud, which I don’t really need but you definitely deserve that money after I’ve discovered PDOModel!), and I am so pleased with JSON export ability which is the one I exclusively use. However, here’s my question/concern:

Can function

arrayToJson($jsonArray);

handle anything else but strings? Since my query returns floats, integers and strings, but JSON only exports strings even though database values are different. Is there an option to handle that situations (especially annoying with id’s, for example) or can you implement that in future versions?

Basically, this is the only thing I find as a drawback to your script so far, great work!

With my best,

Bruno

Greetings,

<?php require_once 'script/PDOModel.php'; $pdomodel = new PDOModel(); $pdomodel->connect("test.sqlite3", "", "", "test.sqlite3", "sqlite", "utf8"); $result = $pdomodel->executeQuery("SELECT * FROM foo"); echo $pdomodel->arrayToJson($result); ?>

This is database structure: http://imgur.com/a/Ys5OD (https://www.pci-z.com/db/test.sqlite3) (integer, text and real) and here’s the output:

https://www.pci-z.com/db/test.php (for some reason pasting JSON in comments doesn’t work, so here’s the link to the output)

As you can see, “id” and “fl” are both represented as strings in JSON, whereas they should be integer and float respectively.

Hi

I have understood the issue. It depends on php version and database you are using.

https://stackoverflow.com/questions/1390983/php-json-encode-encoding-numbers-as-strings

Please refer to above article for better explanation.

Solution: If you are using php > 5.3 then you can do following change in the function arrayToJson() line 1320 in pdomodel.php return json_encode($jsonArray, JSON_NUMERIC_CHECK );

I will add that in future version also.

Thanks

I am using PHP above 5.3 and your fix works like a charm! Brilliant product, once again, thank you so much!

good morning

I have a question is it possible to use avg function with this class??

thanks!!

Good Morning

Yes, you can use avg function also.

Thanks

Hi, my licence ist 723fbda4-6a4e-4c99-8918-1f4b6f421418

I have the problem to update data like

$updateData = array(“validto”=>$validto); $pdomodel->where(“person_id”, $index); $pdomodel->where(“club_Id”, $currentClub); $pdomodel->where(“validto”, NULL); $pdomodel->update(“person_club”, $updateData);

I think the problem is column validto. It is not updating.

My question: How kann I select NULL Values in WHERE condition?

Kind Regards Marcus

Hi,

As per sql standard,

Because NULL stands for UNKNOWN, and when you compare a value with UNKNOWN, the result will always be false.

that’s why it is not working.

Thanks

Hello I have a question, I would like to know if the class allows working with stored procedures in mysql.

Thank you so much!!

Hi,

There is no separate function for that. You can use execute query function to call stored procedure.

Thanks

Hello! Your script is great, I have another question, how can I do to put column names in the first row when i export an excel file?

Hello! Your script is great, I have another question, how can I do to put column names in the first row when i export an excel file?

Hello! this looks great, I have a pre-sales question. I need to give a front end to my wordpress registered users so they can upload a xls or cvs file into a table in my mysql db. Will I be able to give that capability to my users with this system? thanks!

Hi,

I have replied to your similar question in other message thread.

Hi, how can I use RAND in orderByCols? thank you

Hi, thanks for your reply, but that does not work

$this->db->backticks = ””; $this->db->orderByCols = array(“rand()”); $this->db->limit = “0,1”; $results = $this->db->select(“table”);

Works like this:

$results = $this->db->executeQuery(“SELECT * FROM table ORDER BY RAND LIMIT 0,1”);

why?

Hi

check like this also $this->db->orderByCols = array(“rand()”);

try to print query, this will explain. Thanks

thank you!

HELLO! I need a plugin so new users can register and then from the website create a table that only this user can have access, the table should be created uploading a Excel file to mysql dB. Same for many users. Can I have this with this plugin?

Hi, This feature is not available in this script. Thanks

Hi, I’ve already asked you something similar, but I want to confirm, to prevent sql injection is it enough to apply the way you use your script in the examples you have? Or should I do something else? thank you

Hi, Yes, it is using PDO method to connect to database and as mentioned in PDO connection, it is secure against sql injection.

Thanks

Thank you

does the table generated has pagination?

Hi,

It is basically query helper so it doesn’t have many function related to table and pagination. I think you should check this one

https://codecanyon.net/item/pdocrud-advanced-php-crud-application-database-management-system/17674879

Thanks

Hey there,

How can i check if there is already a row with a specefic name? Sort of Count()...?

Greets, Cherimo

Hi,

I am not able to understand your question. Please explain. Just to let you know for complex queries use executeQuery function.

Thanks

Heyy,

For an example, this how i check if a row exist.

$dbPDO->where(“name”,$_POST[‘form_name’]); $dbPDO->where(“id”,$getID,’!=’); $result = $dbPDO->select(“forms”);

if(count($result)...

Is there an easier way?

Hi,

You are doing that correctly. No shortcut method available for that. Thanks

Hi, Every file from demo folder that I access gives me this error: Fatal error: Uncaught Error: Call to a member function prepare() on null in D:\EasyPHP\eds-www\PDOModel\script\PDOModel.php:446 Stack trace: #0 D:\EasyPHP\eds-www\PDOModel\demo\html-export.php(19): PDOModel->select(‘emp’) #1 {main} thrown in D:\EasyPHP\eds-www\PDOModel\script\PDOModel.php on line 446 and I see that all errors are related to this code: $stmt = $this->dbObj->prepare($this->sql);

Am I doing something wrong?

I am using Nginx 1.12.0 PHP 7.1.3×86 or PHP 5.6.30×86 MySQL 5.7.17×86

Hi,

It is giving error that suggest that object is not created. Please check whether it is able to connect to database or not. Make sure all credentials are correct. In case of still issue, give me FTP and db access via email, I will check. Thanks

I have used this code here https://pastebin.com/2c6iffAP to test the connection to db (here is a screenshot with the results http://prntscr.com/ewt02c). If I use mysqli to connect to db it works but not with pdo. Now I’m wondering, knowing that in both cases I didn`t use a pass to connect to db, can pdo connect to a db with no pass?

Hi, as for sql injections, do you have that controlled in your script?

we are using PDO with proper data binding so it’s safe from sql injection. Thanks

Thank you

by
by
by
by
by
by

Tell us what you think!

We'd like to ask you a few questions to help improve CodeCanyon.

Sure, take me to the survey