GithubHelp home page GithubHelp logo

tschoffelen / db.php Goto Github PK

View Code? Open in Web Editor NEW
103.0 103.0 62.0 45 KB

๐ŸŽ Simple PHP class for doing standard MySQL actions, such as select, insert, update and delete rows.

PHP 100.00%

db.php's Introduction

๐Ÿ‘‹ Hi, I'm Thomas.

I'm a co-founder of several tech startups, building tools to help small businesses and educators. I love consulting founders and engineers on everthing from starting their own company to architecting complex applications.

You can find my open source work in the Includable organization.


schof.co โ†’

db.php's People

Contributors

codelingobot avatar craiem avatar nydacatapang avatar pierreg89 avatar tschoffelen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

db.php's Issues

Where between is not working

Hello,
I would like to do this request, but it's not working, could you help me?

$db->select($table, [
'latitude' => 'Between "48.864690367882"',
'latitude' => '"48.900663232118"'
], false, false)->result();

The request SQL is : SELECT * FROM table WHERE latitude Between "48.864690367882" And "48.900663232118" And longitude Between "2.2993563961954" And "2.3540594038046"

Thank you in advance

Particular query

Ho can i do inner join or query with " ... WHERE NOT EXISTS ... "?
My query is that:

SELECT id, *, *, *, *, *,* FROM $tblPosts WHERE NOT EXISTS (SELECT whoBlock FROM $tblBlock WHERE user_id = whoIsBlock AND whoBlock = $id) AND NOT EXISTS (SELECT whoBlock FROM $tblBlock WHERE user_id = whoBlock AND whoIsBlock = $id) AND deleted = FALSE ORDER BY date DESC

charset issue

Hi
thanks for this nice class its useful but there is one problem with it there and you can fix it by adding set_charset to utf8

add this line
$this->mysql->set_charset("utf8");
after
$this->mysql = mysqli_connect($host, $username, $password, $database_name);

unable to set NULL

Hi,

Can't update something to NULL.
By my side, updating int put 0 into it and updating string puts '' (nothing) but not NULL (that is the default value, it can be null).

so

$db->update('myTable', array('Name' => NULL, 'Number' => NULL ... makes '' into Name and 0 into Number

is there a way to set Null or this really is an issue?

Plus I think readme has still little error:

$db->row_array() returns the first row that matches the query as an object (stdClass)

mismatch in readme

$db->row() returns the first row that matches the query as an array
$db->row_array() returns the first row that matches the query as an object (stdClass)

should be the opposite, of course

by the way, very nice and simple class, testing it now, seems to do the job perfectly!

Fatal Error with long queries ?

Not confirmed 100% that it is not an error by my side but, here is what I have:

Fatal error: Uncaught DatabaseException: Database error: MySQL server has gone away in /home/xxx/Database.php:79 Stack trace: #0 /home/xxx/Database.php(490): Database->_error('MySQL server ha...') #1 /home/xxx/mycode.php(275): Database->update('mytable', Array, Array) #2 {main} thrown in /home/xxx/Database.php on line 79

EVERYTIME I try to update it within PHP code with this library, BUT when I try the same query (the query echo'ed on line 386 of Database.php) directly in phpMyAdmin, it works.

Here is what it's like for info.:

UPDATE mytable SET idz='2951;1325;1104;1364;4025;1335;460;4169;6052;6053;339;3579;3580;3577;3610;3611;3582;4076;5272;1342;1321;1361;1331;1360;1332;1358;1349;2053;1359;3597;2142;3595;4075;720;3142;5422;2289;3600;4079;2636;2619;2622;2635;3911;3823;4088;4093;4084;4081;119;5425;486;3571;3609;3592;1347;4618;4621;4617;4607;3809;5682;3617;802;808;178;177;174;1196;1186;175;176;2375;2381;2378;2372;2377;2379;1003;1026;872;909;4115;4111;4113;4109;4119;3589;3603;3588;3607;3925;336;1362;1354;1345;1344;1328;1339;1329;1340;1183;5169;3690;462;457;464;1115;109;5319', idz_dates='2018-11-13 22:35:13;2018-11-13 22:35:13;2018-11-13 22:35:14;2018-11-13 22:35:14;2018-11-13 22:35:14;2018-11-13 22:35:15;2018-11-13 22:35:15;2018-11-13 22:35:16;2018-11-13 22:35:16;2018-11-13 22:35:17;2018-11-13 22:35:17;2018-11-13 22:35:18;2018-11-13 22:35:18;2018-11-13 22:35:19;2018-11-13 22:35:19;2018-11-13 22:35:19;2018-11-13 22:35:20;2018-11-13 22:35:20;2018-11-13 22:35:21;2018-11-13 22:35:21;2018-11-13 22:35:22;2018-11-13 22:35:22;2018-11-13 22:35:23;2018-11-13 22:35:24;2018-11-13 22:35:24;2018-11-13 22:35:25;2018-11-13 22:35:25;2018-11-13 22:35:26;2018-11-13 22:35:26;2018-11-13 22:35:27;2018-11-13 22:35:27;2018-11-13 22:35:28;2018-11-13 22:35:29;2018-11-13 22:35:29;2018-11-13 22:35:30;2018-11-13 22:35:31;2018-11-13 22:35:31;2018-11-13 22:35:31;2018-11-13 22:35:31;2018-11-13 22:35:32;2018-11-13 22:35:32;2018-11-13 22:35:32;2018-11-13 22:35:33;2018-11-13 22:35:33;2018-11-13 22:35:33;2018-11-13 22:35:33;2018-11-13 22:35:34;2018-11-13 22:35:34;2018-11-13 22:35:35;2018-11-13 22:35:35;2018-11-13 22:35:36;2018-11-13 22:35:36;2018-11-13 22:35:36;2018-11-13 22:35:36;2018-11-13 22:35:37;2018-11-13 22:35:37;2018-11-13 22:35:38;2018-11-13 22:35:38;2018-11-13 22:35:38;2018-11-13 22:35:39;2018-11-13 22:35:39;2018-11-13 22:35:39;2018-11-13 22:35:40;2018-11-13 22:35:41;2018-11-13 22:35:41;2018-11-13 22:35:41;2018-11-13 22:35:42;2018-11-13 22:35:42;2018-11-13 22:35:43;2018-11-13 22:35:43;2018-11-13 22:35:43;2018-11-13 22:35:43;2018-11-13 22:35:44;2018-11-13 22:35:45;2018-11-13 22:35:45;2018-11-13 22:35:46;2018-11-13 22:35:46;2018-11-13 22:35:46;2018-11-13 22:35:47;2018-11-13 22:35:47;2018-11-13 22:35:48;2018-11-13 22:35:48;2018-11-13 22:35:49;2018-11-13 22:35:49;2018-11-13 22:35:49;2018-11-13 22:35:49;2018-11-13 22:35:50;2018-11-13 22:35:51;2018-11-13 22:35:51;2018-11-13 22:35:51;2018-11-13 22:35:51;2018-11-13 22:35:52;2018-11-13 22:35:52;2018-11-13 22:35:52;2018-11-13 22:35:52;2018-11-13 22:35:53;2018-11-13 22:35:53;2018-11-13 22:35:53;2018-11-13 22:35:53;2018-11-13 22:35:54;2018-11-13 22:35:54;2018-11-13 22:35:54;2018-11-13 22:35:54;2018-11-13 22:35:55;2018-11-13 22:35:55;2018-11-13 22:35:55;2018-11-13 22:35:56;2018-11-13 22:35:56;2018-11-13 22:35:57;2018-11-13 22:35:57', idz_links='0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0', idz_prices='0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0', idz_quantities='1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1;1' WHERE some_condition='is_like_this'

generated by

$db->update('mytable', ['idz' => implode(";", $idz_array), 'idz_dates' => implode(";", $dates_array), 'idz_links' => implode(";", $links_array), 'idz_prices' => implode(";", $prices_array), 'idz_quantities' => implode(";", $quantities_array)], ["some_condition" => $is_like_this]);

While loop

How can someone use while loop like this?

$result = mysqli_query($conn, "select...");
while($row = mysqli_fetch_assoc($result))
{
// code ...
}

I had use $db->select(); for exec select query, but I don't understand how do loop with mysqli_fetch_assoc

Thanks for answer, and sorry for my English

Multiple ids

I have some Status that are made with numbers or 1 or 2 chars (AA for ex. below).

After having seen your readme, I tried without success:

$db->select('some_table', ['Status' => 'in (0,"AA")'], false, false, 'OR')->result_array();

I also tried only with numbers without success:

$db->select('some_table', ['Status' => 'in (0,1)'], false, false, 'OR')->result_array();

So I had to write this, to make it work:

$db->select('some_table', "Status IN (0, 'AA')")->result_array();

Is this normal?

Thanks.

SQLite3

Is it possible to use SQLite3 instead of MySQL?

$db = new SQLite3('test.db');

Fatal error: Uncaught Error: Call to undefined method SQLite3::select() in teste.php:5 Stack trace: #0 {main} thrown in test.php on line 5

Thank you very much!
Best regards

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.