GithubHelp home page GithubHelp logo

initphp / database Goto Github PK

View Code? Open in Web Editor NEW
5.0 1.0 0.0 255 KB

This library uses PDO. It offers DBAL, Data Mapper, Query Builder and ORM.

License: MIT License

PHP 100.00%
php php7 php-pdo php-pdo-mysql php-pdo-sqlite orm dbal query-builder sql sql-query-builder

database's People

Contributors

muhammetsafak avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

database's Issues

Why we have to use composer with simple php class?

Hi,
Why we have to use composer as apposed to putting php files in a folder and start using them?
Isn't this a simple php class? or people simply want to make things harder in order to impress others?

arabic problem when insert

hi
i have a problem with insert arabic in my database it's showing "????" in database
i check every thing
table charset is utf8mb4_general_ci

	\InitPHP\Database\Facade\DB::createImmutable([
		'dsn'       => "mysql:host={$database['host']};port={$database['port']};dbname={$database['db']};charset=utf8mb4",
		'username'  => $database['user'],
		'password'  => $database['pass'],
		'charset'   => 'utf8mb4',
		'collation' => 'utf8mb4_general_ci',
		'debug'     => true, // boolean
	]);
i check $_POST['username']; before insert and it's arabic
i check page meta is "utf-8"
i try insert arabic using phpmyadmin and all good
sorry for my poor english
any help please ?

2.0.5 için planlanan değişiklikler

Loglama; credentials içinde bir log değeri olarak;

  • Dosya yolu (path) belirtilmiş ise; hataya sebep olan SQL cümleleri ilgili log dosyasına hata ile birlikte eklenmeli
  • PSR-3 standartlarında bir logger nesnesi/object tanımlanmış ise; critical() metoduna SQL cümlesi hata iletisi ile birlikte verilir.
  • Callable bir işlev tanımlanırsa hata iletisi SQL cümlesi ile birlikte callable yönteme string bir parametre olarak verilir.

update with column has restracted word

use \InitPHP\Database\Facade\DB;
$data = [
    'title'     => 'New Title',
    'order'     => '1',
'content'   => 'New Content',
];

$isUpdate = DB::from('post')
                ->where('id', 13)
                ->update($data);
    
/**
* This executes the following query.
* 
* UPDATE post 
* SET title = "New Title", content = "New Content"
* WHERE id = 13
*/
if ($isUpdate) {
    // Success
} else {
    $errors = DB::getError();
    foreach ($errors as $errMsg) {
        echo $errMsg;
    }
}

Firstly thanks for nice library :D and please keep good updating of it

this code above will give error
Fatal error: Uncaught InitPHP\Database\Exceptions\SQLQueryExecuteException: SQLSTATE[42000]: Syntax error or access violation: 1064 You
have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'order = 1

the problem is column "order" is restracted in mysql and must escaped with ``
how to do that with update function ??

toAssoc returns a single array when result has 1 result

I noticed that the Result->toAssoc() function returns a single array when the result has 1 row. That is, the array returned is not an array of associative arrays. So it makes it inconsistent when looping over the values. For example.

DB::table('test')->where('name', 1)->get()->toAssoc(); // returns
// [ 'name' => 'test ]

// next
DB::table('test')->get()->toAssoc(); // returns
//[ [ 'name' => 'test'], ['name' => 'test2'], ... ]
  

help with "replace into"

how to use replace into with initPHP\Database library ?

example

$data = array(
    array('id' => 1, 'name' => 'John'),
    array('id' => 2, 'name' => 'Jane'),
    // Add more data as needed
);

// Prepare the SQL statement
$sql = "REPLACE INTO your_table (id, name) VALUES (:id, :name)";

// Prepare the PDO statement
$stmt = $pdo->prepare($sql);

// Iterate through the data and execute the statement for each set of values
foreach ($data as $row) {
    try {
        $stmt->execute($row);
        // Handle success or log if needed
    } catch (PDOException $e) {
        // Handle error or log if needed
        echo "Error: " . $e->getMessage();
    }
}

I see you have updated your library and many files have been removed!!
If I update the library in my project will there be any problem?

showing errors

hi
how to show errors when $isUpdate is false ??

<?php
use \InitPHP\Database\Facade\DB;
$data = [
    'title'     => 'New Title',
    'content'   => 'New Content',
];



$isUpdate = DB::from('post')
                ->where('id', 13)
                ->update($data);
    
/**
* This executes the following query.
* 
* UPDATE post 
* SET title = "New Title", content = "New Content"
* WHERE id = 13
*/
if ($isUpdate) {
  echo 'Success';
} else {
// show errors here
}

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.