GithubHelp home page GithubHelp logo

mrcrypster / mysqly Goto Github PK

View Code? Open in Web Editor NEW
24.0 3.0 7.0 138 KB

Full-featured opensource small-overhead PHP data framework for Mysql built for fast and efficient development

Home Page: https://mysqly.com

License: MIT License

PHP 100.00%
php mysql cache job-queue stored-procedures pdo pdo-mysql php-database php-key-value-store mysql-cache opensource cache-storage key-value database sql

mysqly's Introduction

Mysqly is a full-featured opensource small-overhead PHP data framework for Mysql built for fast and efficient development.

Install

wget https://mysqly.com/mysqly.php

Usage example

require 'mysqly.php'; # include library (single file)
mysqly::auth('user', 'pwd', 'db', '127.0.0.1'); # connect to Mysql server

// Dynamic methods for table names
$users = mysqly::users(['age' => 25]); # SELECT * FROM users WHERE age = 25
$user = mysqly::users_(6); # SELECT * FROM users WHERE id = 6 LIMIT 1

// And many more features ↓

All features & documentation

Download mysqly

mysqly's People

Contributors

everstudent avatar mrcrypster 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

Watchers

 avatar  avatar  avatar

mysqly's Issues

Multi insert issue

Hi, i have just started using mysqly.php library. I have an issue when calling:

mysqly::multi_insert('facts_union', $insert);

Below I am sending var_dump for $insert array and also var_dump for $params in your public static function exec() function. As you can see the column binding is getting mixed up. Only for first insert statement this order seems ok, but for the second and third the binding starts with "r:10" instead of "r:00". And the next array member starts with "r:20" etc. Am I doing something wrong? Is there a limit to columns number or something? I am not very good in php :)

`C:\inetpub\wwwroot...\test.php:224:
array (size=3)
0 =>
array (size=22)
'GENDER' => string 'male' (length=4)
'ID_P_F' => string '19' (length=2)
'YEAR_F' => string '2004' (length=4)
'TMW_F' => string '74' (length=2)
'TML_F' => string '6' (length=1)
'TBW_F' => string '21' (length=2)
'TBL_F' => string '5' (length=1)
'MF_F' => string '74' (length=2)
'ACES_F' => string '557' (length=3)
'DF_F' => string '152' (length=3)
'SRV1_F' => string '62' (length=2)
'WON1_F' => string '78' (length=2)
'WON2_F' => string '58' (length=2)
'SGW_F' => string '92' (length=2)
'BPS_F' => string '73' (length=2)
'PWR1S_F' => string '35' (length=2)
'PWR2S_F' => string '52' (length=2)
'BPW_F' => string '41' (length=2)
'RGW_F' => string '30' (length=2)
'PRIZE_F' => string '6357547' (length=7)
'JobID' => int -1
'JobTimestamp' => string '2023-01-12 12:24:09' (length=19)
1 =>
array (size=22)
'GENDER' => string 'male' (length=4)
'ID_P_F' => string '89' (length=2)
'YEAR_F' => string '2004' (length=4)
'TMW_F' => string '74' (length=2)
'TML_F' => string '16' (length=2)
'TBW_F' => string '36' (length=2)
'TBL_F' => string '11' (length=2)
'MF_F' => string '81' (length=2)
'ACES_F' => string '1017' (length=4)
'DF_F' => string '186' (length=3)
'SRV1_F' => string '63' (length=2)
'WON1_F' => string '81' (length=2)
'WON2_F' => string '56' (length=2)
'SGW_F' => string '91' (length=2)
'BPS_F' => string '69' (length=2)
'PWR1S_F' => string '29' (length=2)
'PWR2S_F' => string '50' (length=2)
'BPW_F' => string '40' (length=2)
'RGW_F' => string '22' (length=2)
'PRIZE_F' => string '2604590' (length=7)
'JobID' => int -1
'JobTimestamp' => string '2023-01-12 12:24:09' (length=19)
2 =>
array (size=22)
'GENDER' => string 'male' (length=4)
'ID_P_F' => string '7' (length=1)
'YEAR_F' => string '2004' (length=4)
'TMW_F' => string '68' (length=2)
'TML_F' => string '18' (length=2)
'TBW_F' => string '18' (length=2)
'TBL_F' => string '9' (length=1)
'MF_F' => string '84' (length=2)
'ACES_F' => string '523' (length=3)
'DF_F' => string '303' (length=3)
'SRV1_F' => string '54' (length=2)
'WON1_F' => string '75' (length=2)
'WON2_F' => string '53' (length=2)
'SGW_F' => string '82' (length=2)
'BPS_F' => string '64' (length=2)
'PWR1S_F' => string '34' (length=2)
'PWR2S_F' => string '53' (length=2)
'BPW_F' => string '43' (length=2)
'RGW_F' => string '32' (length=2)
'PRIZE_F' => string '2766051' (length=7)
'JobID' => int -1
'JobTimestamp' => string '2023-01-12 12:24:09' (length=19)

C:\inetpub\wwwroot...\mysqly.php:103:
array (size=66)
':r00' => string 'male' (length=4)
':r01' => string '19' (length=2)
':r02' => string '2004' (length=4)
':r03' => string '74' (length=2)
':r04' => string '6' (length=1)
':r05' => string '21' (length=2)
':r06' => string '5' (length=1)
':r07' => string '74' (length=2)
':r08' => string '557' (length=3)
':r09' => string '152' (length=3)
':r010' => string '62' (length=2)
':r011' => string '78' (length=2)
':r012' => string '58' (length=2)
':r013' => string '92' (length=2)
':r014' => string '73' (length=2)
':r015' => string '35' (length=2)
':r016' => string '52' (length=2)
':r017' => string '41' (length=2)
':r018' => string '30' (length=2)
':r019' => string '6357547' (length=7)
':r020' => int -1
':r021' => string '2023-01-12 12:24:09' (length=19)
':r10' => string 'male' (length=4)
':r11' => string '89' (length=2)
':r12' => string '2004' (length=4)
':r13' => string '74' (length=2)
':r14' => string '16' (length=2)
':r15' => string '36' (length=2)
':r16' => string '11' (length=2)
':r17' => string '81' (length=2)
':r18' => string '1017' (length=4)
':r19' => string '186' (length=3)
':r110' => string '63' (length=2)
':r111' => string '81' (length=2)
':r112' => string '56' (length=2)
':r113' => string '91' (length=2)
':r114' => string '69' (length=2)
':r115' => string '29' (length=2)
':r116' => string '50' (length=2)
':r117' => string '40' (length=2)
':r118' => string '22' (length=2)
':r119' => string '2604590' (length=7)
':r120' => int -1
':r121' => string '2023-01-12 12:24:09' (length=19)
':r20' => string 'male' (length=4)
':r21' => string '7' (length=1)
':r22' => string '2004' (length=4)
':r23' => string '68' (length=2)
':r24' => string '18' (length=2)
':r25' => string '18' (length=2)
':r26' => string '9' (length=1)
':r27' => string '84' (length=2)
':r28' => string '523' (length=3)
':r29' => string '303' (length=3)
':r210' => string '54' (length=2)
':r211' => string '75' (length=2)
':r212' => string '53' (length=2)
':r213' => string '82' (length=2)
':r214' => string '64' (length=2)
':r215' => string '34' (length=2)
':r216' => string '53' (length=2)
':r217' => string '43' (length=2)
':r218' => string '32' (length=2)
':r219' => string '2766051' (length=7)
':r220' => int -1
':r221' => string '2023-01-12 12:24:09' (length=19)`

Insert into column type BIT(1) gives truncate-error

When trying to insert a value (0,1,true,false,'0','1') into a column with type BIT(1), I get an error:

Fatal error: Uncaught PDOException: SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column 'active' at row 1 in mysqly.php:99
Stack trace:
#0 mysqly.php(99): PDOStatement->execute(Array)
#1 mysqly.php(324): mysqly::exec('INSERT INTO `TABLE...', Array)
#2 page.php(68): mysqly::multi_insert('TABLE', Array)

Workaround: I changed the columntype to TINYINT(1).

Error also appearce when using single row insert

Comprehensive Documentation Improvement and Feature Enhancement

Objective:
I am interested in contributing to Mysqly by enhancing the documentation to make it more comprehensive and user-friendly, as well as suggesting and implementing feature improvements.

Documentation Improvement:

  1. Add Examples:

    • Create detailed examples and tutorials for different features of Mysqly.
    • Ensure examples cover common use cases and demonstrate the flexibility of the framework.
    • Include examples for:
      • Connecting to a MySQL server.
      • Executing dynamic methods.
      • Using native SQL support.
      • Implementing secure value binding.
      • Handling multiple DB/server connections.
      • Utilizing job queue and cache storage components.
  2. Clarify Usage:

    • Review the current documentation to identify areas that are unclear or lacking in detail.
    • Improve the clarity of usage instructions, making it easier for new users to get started with Mysqly.
    • Break down complex instructions into step-by-step guides.
    • Add troubleshooting tips for common issues.
  3. API Documentation:

    • Ensure that every function and feature is thoroughly documented.
    • Include detailed descriptions of each function’s purpose, parameters, return values, and usage examples.
    • Organize the API documentation in a logical manner for easy navigation.
    • Highlight best practices and performance tips.

Proposed Structure for Documentation:

  1. Introduction:

    • Overview of Mysqly.
    • Key features and benefits.
  2. Installation:

    • Step-by-step installation guide.
  3. Getting Started:

    • Basic usage examples.
    • Quick start guide.
  4. Detailed Examples:

    • Comprehensive tutorials for various features.
    • Real-world use case scenarios.
  5. API Reference:

    • Detailed documentation of all functions and features.
    • Usage examples for each function.
    • Parameters and return values.
  6. Advanced Topics:

    • Performance optimization tips.
    • Security best practices.
    • Handling complex queries and transactions.
  7. Troubleshooting:

    • Common issues and solutions.
    • FAQs.
  8. Community and Support:

    • How to get help.
    • Contribution guidelines.

Feature Enhancements:

  1. New Features:

    • Propose and implement new features that would benefit users, such as additional dynamic methods, support for more SQL operations, or enhanced caching mechanisms.
  2. Optimizations:

    • Identify and implement code optimizations for better performance and lower resource usage.
  3. Security Improvements:

    • Conduct security audits and implement best practices for secure coding to prevent vulnerabilities.

How I Can Help:

  1. Documentation Contributions:

    • Write and review examples and tutorials.
    • Enhance the clarity of existing usage instructions.
    • Document API functions and features in detail.
  2. Feature Development:

    • Propose and implement new features.
    • Optimize existing code for better performance.
    • Improve security measures.
  3. Testing and Quality Assurance:

    • Write unit tests for existing and new features.
    • Report and help fix bugs.
    • Review pull requests to maintain code quality.

Benefits:

  • Improved user experience with clearer and more detailed documentation.
  • Easier onboarding for new users.
  • Increased adoption of Mysqly due to better understanding and usability.
  • Enhanced functionality and performance of the system.

Call to Action:
I look forward to contributing to the improvement of Mysqly and collaborating with other contributors and maintainers to make it even more robust and user-friendly.

Thank you for considering my suggestions and contributions!

RFC: Support of REPLACE INTO

The function insert_update does not work with multiple rows. Could you add the support of the SQL statement REPLACE INTO to your class?

I have now duplicated the insert and multi_insert-function, renamed it to (multi_)replace and changed the query within $sql to:

$sql = "REPLACE INTO `{$table}`

This is working for me, but I would lose it when installing a new release.

IN-array values error

In the documentation you say the placeholder in the SELECT-statement and bind-array can be ":ids". But to make the code work, the placeholder-name in de array needs to be without the colon (":").

Issue is in line 93, where you replace the current placeholder with the new generated placeholders. The search parameter looks for ":" + original placeholder-name in the bind-array. When using ":ids" as placeholder-name, the search-string is actually "::ids". This will return an error (Fatal error: Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number: parameter was not defined in mysqly.php:110)

Example:
$rows = mysqly::fetch( 'SELECT id, age FROM users WHERE id IN (:ids)', [':ids' => [6, 7]] );
will not work and returns an error.
When used as:
$rows = mysqly::fetch( 'SELECT id, age FROM users WHERE id IN (:ids)', ['ids' => [6, 7]] );
it works.
Deleting the ":" on line 93 does not work.

Ps. the , is also missing in the example on the documentation after the SELECT-statement.

Return lastInsertId when using insert_update

When using the insert_update-function, there is no lastInsertId returned. Adding return static::$db->lastInsertId(); at line 318 works.
Could you add this to the source code?

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.