static void Main(string[] args) { /* * Samples */ //using Prepared statement Method 1 NetPDOv2.PDO db = new NetPDOv2.PDO(); db._connect(); db.prepare("select * from table WHERE column1 = @c1 and column2 = @c2"); db.bindValue("@c1", "2"); db.bindValue("@c2", "Value 2"); db.execute(true); //execute(bool isFetch=false) : Optional Parameter isFetch must be true to use fetchAllAsStr and fetchAllAsObj; string StringResult = db.fetchAllAsStr(); //Get response as JSON string JArray JsonResult = db.fetchAllAsObj(); //Gets response as JSON //using Prepared statement Method 2 NetPDOv2.PDO db2 = new NetPDOv2.PDO(); db._connect(); db.prepare("select * from table WHERE column1 = ? AND column2 = ?"); string[] data = { "2", "Value 2" }; db.bindValues(data); db.execute(true); //execute(bool isFetch=false) : Optional Parameter isFetch must be true to use fetchAllAsStr and fetchAllAsObj; string StringResult2 = db.fetchAllAsStr(); //Get response as JSON string JArray JsonResult2 = db.fetchAllAsObj(); //Gets response as JSON /* * DBTransaction Class allows you to do a quick DB transaction */ // Check if row exists usage isExist(query, parameter) NetPDOv2.dbTransactions dbtrans = new NetPDOv2.dbTransactions(); if (dbtrans.isExist("SELECT id FROM table WHERE condition = true", new string[] { "" })) { //Row Exists, do something } //Selects Rows from DB. Usage selectFromQuery(query, parameters, isObj) NetPDOv2.dbTransactions.queryResult result = dbtrans.selectFromQuery("SELECT * FROM table WHERE column = ?", new string[] { "value" }, true); //If Query is successful, result.resultAsObject will return have the result }
public bool isExist(string sql, string[] q) { NetPDOv2.PDO db = new NetPDOv2.PDO(); try { db._connect(); db.prepare(sql); if (!q.Equals(null)) { db.bindValues(q); } db.execute(true); JArray result = db.fetchAllAsObj(); if (!result.Equals(null) && result.Count > 0) { return(true); } return(false); } catch { return(false); } }
public queryResult selectFromQuery(string sql, string[] q, bool isObj = false) { NetPDOv2.PDO db = new NetPDOv2.PDO(); queryResult res = new queryResult(); try { db._connect(); db.prepare(sql); if (!q.Equals(null)) { db.bindValues(q); } db.execute(true); if (isObj) { res.resultAsObject = db.fetchAllAsObj(); res.resultAsString = null; } else { res.resultAsString = db.fetchAllAsStr(); res.resultAsObject = null; } } catch { if (isObj) { res.resultAsObject = null; res.resultAsString = null; } else { res.resultAsString = null; res.resultAsObject = null; } } return(res); }