Skip to content

Simple and small PHP PDO Class for your PHP project

License

Notifications You must be signed in to change notification settings

hyanc/PHPPDOClass

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 

Repository files navigation

PHPPDOClass

PHP Data Object Class. Query method return associative array:

  • Match (return all data in array)
  • Count (return number of rows data)
  • Cols (return columns data)
  • Error & SQL

*Numeric second parameter return content of one cell result

Initialize

include('pdo.php');
$sql = new Database('dbName');

Sample 1. Basic print_r output

$q = $sql->query("select 'frog' as animal, 'hop' as ability");

print_r($q);

/*result
Array
(
    [count] => 1
    [sql] => select 'frog' as animal, 'hop' as ability
    [cols] => Array
        (
            [0] => animal
            [1] => ability
        )

    [match] => Array
        (
            [0] => Array
                (
                    [animal] => frog
                    [ability] => hop
                )

        )

)
*/

Sample 2. HTML table layout

$q = $sql->query("select 'frog' as animal, 'hop' as ability");

echo "<table>";
foreach($q['cols'] as $cols => $col) {
	echo "<th>".$col."</th>";
}
foreach($q['match'] as $rows => $row) {
	echo "<tr>";
	foreach($row as $data) {
		echo "<td>".$data."</td>";
	}
	echo "</tr>";
}
echo "</table>";

Sample 3. One cell result

//second parameter is row number
echo $sql->query("select 'frog' as animal, 'hop' as ability",0);
// frog

Sample 4. Error handling

$q = $sql->query("select 'frog as animal, 'hop' as ability");
if(isset($q['error'])) echo $q['error'];

About

Simple and small PHP PDO Class for your PHP project

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages