{"id":20598417,"url":"https://github.com/kkirsche/pdo-database-class","last_synced_at":"2026-01-27T21:48:22.829Z","repository":{"id":142820606,"uuid":"9888264","full_name":"kkirsche/PDO-Database-Class","owner":"kkirsche","description":"This is a basic PHP based PDO Class","archived":false,"fork":false,"pushed_at":"2013-05-06T15:00:29.000Z","size":102,"stargazers_count":2,"open_issues_count":0,"forks_count":3,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-05-31T23:54:37.848Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kkirsche.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-05-06T14:13:06.000Z","updated_at":"2015-06-24T08:39:57.000Z","dependencies_parsed_at":"2023-05-01T16:42:40.382Z","dependency_job_id":null,"html_url":"https://github.com/kkirsche/PDO-Database-Class","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/kkirsche/PDO-Database-Class","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kkirsche%2FPDO-Database-Class","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kkirsche%2FPDO-Database-Class/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kkirsche%2FPDO-Database-Class/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kkirsche%2FPDO-Database-Class/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kkirsche","download_url":"https://codeload.github.com/kkirsche/PDO-Database-Class/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kkirsche%2FPDO-Database-Class/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28823747,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-27T18:44:20.126Z","status":"ssl_error","status_checked_at":"2026-01-27T18:44:09.161Z","response_time":168,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-16T08:26:46.971Z","updated_at":"2026-01-27T21:48:22.804Z","avatar_url":"https://github.com/kkirsche.png","language":null,"readme":"Using the PDO class\n===================\n\n##Insert a new record\n\nFirstly you need to instantiate a new database.\n\n```php\n$database = new Database();\n```\n\nNext we need to write our insert query. Notice how I’m using placeholders instead of the actual data parameters.\n\n```php\n$database-\u003equery('INSERT INTO mytable (FName, LName, Age, Gender) VALUES (:fname, :lname, :age, :gender)');\n```\n\nNext we need to bind the data to the placeholders.\n\n```php\n$database-\u003ebind(':fname', 'John');\n$database-\u003ebind(':lname', 'Smith');\n$database-\u003ebind(':age', '24');\n$database-\u003ebind(':gender', 'male');\n```\n\nAnd finally we run execute the statement.\n\n```php\n$database-\u003eexecute();\n```\n\nBefore running the file, echo out the lastInsertId function so you will know that the query successfully ran when viewed in the browser.\n\n```php\necho $database-\u003elastInsertId();\n```\n\n##Insert multiple records using a Transaction\n\nThe next test we will try is to insert multiple records using a Transaction so that we don’t have to repeat the query.\n\nThe first thing we need to do is to begin the Transaction.\n\n```php\n$database-\u003ebeginTransaction();\n```\n\nNext we set the query.\n\n```php\n$database-\u003equery('INSERT INTO mytable (FName, LName, Age, Gender) VALUES (:fname, :lname, :age, :gender)');\n```\n\nNext we bind the data to the placeholders.\n\n```php\n$database-\u003ebind(':fname', 'Jenny');\n$database-\u003ebind(':lname', 'Smith');\n$database-\u003ebind(':age', '23');\n$database-\u003ebind(':gender', 'female');\n```\n\nAnd then we execute the statement.\n\n```php\n$database-\u003eexecute();\n```\n\nNext we bind the second set of data.\n\n```php\n$database-\u003ebind(':fname', 'Jilly');\n$database-\u003ebind(':lname', 'Smith');\n$database-\u003ebind(':age', '25');\n$database-\u003ebind(':gender', 'female');\n```\n\nAnd run the execute method again.\n\n```php\n$database-\u003eexecute();\n```\n\nNext we echo out the lastInsertId again.\n\n```php\necho $database-\u003elastInsertId();\n```\n\nAnd finally we end the transaction\n\n```php\n$database-\u003eendTransaction();\n```\n\n##Select a single row\n\nThe next thing we will do is to select a single record.\n\nSo first we set the query.\n\n```php\n$database-\u003equery('SELECT FName, LName, Age, Gender FROM mytable WHERE FName = :fname');\n```\n\nNext we bind the data to the placeholder.\n\n```php\n$database-\u003ebind(':fname', 'Jenny');\n```\n\nNext we run the single method and save it into the variable $row.\n\n```php\n$row = $database-\u003esingle();\n```\n\nFinally, we print the returned record to the screen.\n\n```php\necho \"\u003cpre\u003e\";\nprint_r($row);\necho \"\u003c/pre\u003e\";\n```\n\n##Select multiple rows\nThe final thing we will do is to run a query and return multiple rows.\n\nSo once again, set the query.\n\n```php\n$database-\u003equery('SELECT FName, LName, Age, Gender FROM mytable WHERE LName = :lname');\n```\n\nBind the data.\n\n```php\n$database-\u003ebind(':lname', 'Smith');\n```\n\nRun the resultSet method and save it into the $rows variable.\n\n```php\n$rows = $database-\u003eresultSet();\n```\n\nPrint the return records to the screen.\n\n```php\necho \"\u003cpre\u003e\";\nprint_r($rows);\necho \"\u003c/pre\u003e\";\n```\n\nAnd finally display the number of records returned.\n\n```php\necho $database-\u003erowCount();\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkkirsche%2Fpdo-database-class","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkkirsche%2Fpdo-database-class","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkkirsche%2Fpdo-database-class/lists"}