Sohag Developer PostgreSQL Database Applications

Build Powerful Robust Database Applications

July 2018

Wed, 07/18/2018 - 18:08 - amr

Finally I solved the problem and now I can connect to MariaDb from Qt on fedora linux OS.
Fedora 28, MariaDB-10.2.16 and Qt 5.9.6
After searching for long time I didn't find any solutions, I decided to build the qt mysql driver although there was pre-built driver shipped with Qt 5 .
It works after replacing the pre-built Qt MySQL driver with one I've built.

Tue, 07/17/2018 - 22:31 - amr

Simple Template Class Implementation .cpp


    
#include "employees.h"
#include "ui_employees.h"
#include <QSqlQuery>
#include <QSqlError>
#include <QMessageBox>


Employees::Employees(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Employees)
{
    ui->setupUi(this);
   
    db = QSqlDatabase::database();
   
    newRecord();
   
Tue, 07/17/2018 - 22:29 - amr

The error driver not loaded may has many reason like you don't have the database driver QPSQL plugin in case of PostgreSQL Database Or (QMYSQL plugin if you are tring to connect to MySQL database, QOCI if you are using oracle or other depinding on you database server)
If you are using Qt 4 you have to compile the QPSQL plugin yourself, but if you are using Qt 5 then you have the plugin already compiled.

Tue, 07/17/2018 - 22:29 - amr

Welcome to Qt Database Development Course:
My name is Amr Nassr. In this course I'll show you how to develop a compelete database application from scratch using Qt C++ framework.

I'll begin from analysing the projrct requirments, modeling walking through creating database entity relationship diagram (ERD), crating database tables, views and stored functions.

view.php


<!-- 
** GENERATED BY SOHAG DEVELOPER
** Visit Us: http://sohag-developer.com/
-->
<?php
    require '../conf/database.php';
    $id = null;
    if ( !empty($_GET['id'])) {
        $id = $_REQUEST['id'];
    }
     
    if ( null==$id ) {
        header("Location: index.php");
    } else {
        $pdo = Database::connect();
        $sql = "SELECT *columnsListSperatedByComma* FROM *tabelName* WHERE *primaryKeyColumn* = ?";
        $q = $pdo->prepare($sql);
        $q->execute(array($id));

delete.php


<!-- 
** GENERATED BY SOHAG DEVELOPER
** Visit Us: http://sohag-developer.com/
-->
<?php
    require '../conf/database.php';
	$id=0;
    if ( !empty($_GET['id'])) {
	$id = $_REQUEST['id'];	
	}
	
    if ( !empty($_POST)) {
	$id = $_POST['id'];         
        $pdo = Database::connect();
        $sql = "DELETE FROM *tabelName*  WHERE *primaryKeyColumn* = ?";
        $q = $pdo->prepare($sql);
        $q->execute(array($id));
        header("Location: index.php");
    }
?>
 
<?php
require '../templates/header.php';

edit.php


<!-- 
** GENERATED BY SOHAG DEVELOPER
** Visit Us: http://sohag-developer.com/
-->
<?php
    require '../conf/database.php';
 
    $id = null;
	
    if ( !empty($_GET['id'])) {
        $id = $_REQUEST['id'];
    }
     
    if ( null==$id ) {
        header("Location: index.php");
    }
     
    
    $pdo = Database::connect();
    if ( !empty($_POST)) {

*postVariables*
         
            $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

Pages