0 Members and 1 Guest are viewing this topic.
Well, I would go for mySQL as it is easy to implement with PHP and mySQL is fun.But then again, i wrote for withg a blog which uses system-msg as a backend which uses markdown, it can be found here: http://withg.org/blog/
Quote from: Sorunome on February 18, 2014, 04:45:43 pmWell, I would go for mySQL as it is easy to implement with PHP and mySQL is fun.But then again, i wrote for withg a blog which uses system-msg as a backend which uses markdown, it can be found here: http://withg.org/blog/Well, system-msg already stored to flat files, you just wrote a web interface for it instead of using it as a backend.
INSERT INTO `blog_posts` (post,whateverOtherColumnsYouWantToSet) VALUES ('%s','%s')
UPDATE `blog_posts` SET post='%s' WHERE postId=%d
SELECT post,name,whatever FROM `blog_posts` WHERE postId`%d
class Sql{ private $mysqliConnection; private $queryNum; public function __construct(){ $this->queryNum = 0; } private function connectSql(){ if(!isset($this->mysqliConnection)){ //if no connection yet we create one $this->mysqliConnection = new mysqli('localhost','sql_user','sql_password','sql_database'); if ($this->mysqliConnection->connect_errno) die('Could not connect to SQL DB: '.$this->mysqliConnection->connect_errno.' '.$this->mysqliConnection->connect_error); $this->mysqliConnection->autocommit(true); } } public function query($query,$args = [],$num = false){ $this->connectSql(); //connect to sql for($i=0;$i<count($args);$i++) //escape arguments $args[$i] = $this->mysqliConnection->real_escape_string($args[$i]); $result = $this->mysqliConnection->query(vsprintf($query,$args)); //insert arguments in query and execute it $this->queryNum++; //add one to the query counter if($this->mysqliConnection->errno==1065) //empty return array(); if($this->mysqliConnection->errno!=0) die($this->mysqliConnection->error.' Query: '.vsprintf($query,$args)); if($result===true) //nothing returned return array(); $res = array(); $i = 0; while($row = $result->fetch_assoc()){ $res[] = $row; if($num!==false && $i===$num){ //if the user set an element then we only reaturn that one $result->free(); return $row; } if($i++>=150) //we don't want php to mem overflow break; } if($res === []){ //if the result is empty we create a dummy array with the assoc fields, each containing NULL $fields = $result->fetch_fields(); for($i=0;$i<count($fields);$i++) //create each field and set it to NULL $res[$fields[$i]->name] = NULL; if($num===false) //if we didn't set an element we expect it to be an array in an array $res = array($res); } $result->free(); return $res; //return the result }}$sql = new Sql();
$res = $sql->query("SELECT * FROM `blog_posts` WHERE id=%d",[$number]);
$res = $sql->query("SELECT * FROM `blog_posts` WHERE id=%d",[$number],0);
$sql->query("INSERT INTO `blog_posts` (post,name) VALUES ('%s','%s')",[$post,$name]);
oh, ok, nice! But i would still use the single quotes on strings