Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class database_statements{
- var $error_in_connection = 'Unable to connect to database at this time.';
- function database_connection(){
- try{
- // Establishes a database connection
- $dsn = 'mysql:host=localhost; dbname=data; charset=latin1';
- $username = 'root';
- $password = '';
- $connection = new PDO($dsn, $username, $password);
- return $connection;
- }
- catch(Exception $ex){}
- }
- function database_crud($statement, $value = array()){
- // ...passes the sql statements and insert the value into the array
- // ... the function performs CRUD functions
- try {
- $db = $this->database_connection();
- $insert_data = $db->prepare($statement);
- for ($i = 1; $i <= count($value); $i++){
- $insert_data->bindValue($i, $value[$i-1]);
- }
- $insert_data->execute();
- }
- catch (Exception $ex) {
- echo $this->error_in_connection;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement