Inserting and retrieving data from MySQL database from AngularJS site - javascript

As a learning project I have been using AngularJS to create a quiz website. I having a web hosting package with 123-reg.co.uk and managed to create a MySQL database with a table I hope to store peoples scores who complete the quiz.
Ultimately this means I will be able to build a scoreboard on my site. I am hoping to create two functions in my site, one which will retrieve the scores and one which will post new scores. I believe in order to achieve this I will need to use PHP to retrieve and post data however I am a little unsure where to start.
If anyone could provide me with some pointers I would be grateful as I am not particularly familiar with MySQL databases or PHP. I did find this guide on connecting to MySQL database from 123reg.co.uk however I am struggling.
Thanks,
Simon

The tutorial that you mentioned is outdated, relies on mysql_connect that was deprecated in PHP 5.5.0 and removed on PHP 7.0.0. Find a more up to date tutorial that uses mysqli or PDO.
Also you will need to learn some security concerns, I really recommend you to study a bit before doing this, since you can have serious problems if implement a insecure script to do this.
There are great PHP Frameworks that implement all of this in a secure and easy way, try searching for Laravel Framework. Isn't for begginers, but with a little knowlegend of PHP Object-oriented and MySQL (or any SQL supported by Laravel) you can do what you want.
There are also a nice site to learn Laravel, called Laracasts with very nice screen-casts teaching Laravel (for begginers or not).

Related

Approach for adding posts to a blog type website

I've created a blog style website using html, CSS and bootstrap. I've recently started learning Javascript.
I want to be able to add/delete posts etc to the blog website. Is Javascript the technology I should be using to do to this? I also thought I could use SQL or something to create a database and somehow have posts be loaded onto the site from the database.
I'm pretty new to all this so I'm not too sure.
Help appreciated.
What you need is some sort of storing the objects on a server. You can choose from plethora of solutions, naming php and nodejs as most popular ones in web world. On the server you (most of the times) make a connection to the database (sql - mysql, mariadb etc or nosql like mongodb for example) in order to get or set or remove some objects (posts). You can as well store it in files or whatever you want, but database is just created to serve this purpose. Has numerous advantages over another solutions.
And now to the Javascript; you can use it to send the data asynchronously (read about ajax / xhr request) but its completely optional. It's definetely not the core of the proces and it's completely ommitable.
You can build anything from scratch, and such experiments are sometimes beneficial, but most of the times you just want to use some de-facto standard technology that has most of the pitfalls covered and offers you good development experience as well as security benefits (wordpress - cms, symfony frsmework).

How do I connect a sql server to my Javascript game?

I'm working on a project and I just need a holistic overview on how to go about it.
I'm going to use HTML/CSS canvas to make the game.
However, the game involves visualization of large amounts of data that is best served in a database. What I do not know how to do is:
Link my HTML/CSS game to a SQL database
Parse a text file to populate the database.
I don't have specific issues I just don't even know where to start? Some people have said AJAX? Others have said parse.com?
You have two options:
write a server-side application to serve data from a DB
use client-side HTML5 storage (such as local storage, WebSQL, IndexedDB, etc)
If you use the server implementation you will need AJAX to communicate with the server.
To do this you will have toove beyond JavaScript and learn server side programming. The good news is there are tons of awesome server side languages that make building websites easy.
If you come from a javascript background, ruby would probably be an easy transition. I'd suggest Sinatra.
If you are using SQL server, c# and asp.net are great choices that are very well designed, thou c# is very different from JavaScript as a language.
Like python? Web2py and Django are good.
Then there is PHP and java...
You would probably write an API in one of these server side languages, access it using Ajax to retrieve Jason and process it.
And don't bother with parse.com. write your own parser in the language of your choice. Its usually really easy, and instructive.
I think you already know a language you can use. How about javascript? Of course a real serverside language like Java or PHP would be better - maybe as already told: ruby but why not try it with node.js:
Node.js could be the first thing you may look at. (http://nodejs.org/)
It's really nice & well documented - there is also a big question about node.js with mysql: MySQL with Node.js which also works fine.

Is Node.js suitable for my project given how I'm using it?

I'm about to start writing an application and I want to include newer technologies to improve my knowledge and gain a skill set.
I'm using mysql to store user data (no choice), Angular.js to display/template content on the dom, and I wanted to use node.js to return results from the database in json format to be used by Angular.js.
My assumption was I could use node.js (along with the node-mysql module and maybe express)to accomplish my database queries that feed into my Angular.js templates.
Additionally, the application will live on a different server than the database itself and may reside in a mobile framework.
Am I way off base when it come to how to use node.js? Am I just using the wrong tool? Am I on the right track?
Any help, explanation, and points in the right direction would be great. Most of the info I've seen are copy/paste from the node.js site/wiki and don't really answer my question.
This is largely an opinion-based question and likely to be closed, but you're not way off base. What you want to do is absolutely (and commonly) done using Node.js.
As a complete aside, you might like to check out Platform-as-a-Service providers such as Heroku.com and Nodejitsu.com; both offer great and easy Node.js hosting and addons (such as NoSQL and RDBMS data stores) which have free tiers.
For that matter, MongoLab and MongoHQ both offer free tiers independent of Heroku, which you could use from your MySQL-only hosting provider if you like.

Broad Design Implementation: PHP, MySQL, Knockout

Spent the last few weeks learning MySQL and PHP. Then I learned some basic knockout.js and I'm rewriting a lot of things.'
Just wanted to check before I go further if this is the most efficient way of doing things with PHP/MySQL/Knockout.js-
Pages are php with Knockout which is pulling and pushing data via ajax/Json to separate php files which then push to MySQL. The login system is PHP & MySQL. And I'm using $_SESSION variables to limit content (its a project management system) to what each user is allowed to access.
Is this the current way of doing things? Or am I still behind the times
thanks!
-newb
knockout is the way to go, maybe in combination with jquery in the client side you are good to go, but i recommend you to use a php framework for the server side like codeigniter, zend, symfony there are lots of them, i am currently using codeigniter + jquery + knockout and is boosting me a lot. hope this will help you

Accounts in serverside JavaScript (node.js)

I'm making an online game and I was wondering - how can users create accounts? Do I need a database, and if yes, which one? Also how do I get information from the users? I believe by using html tag, but how exactly? I'm not using PHP for the serverside, but node.js.
There are so many answers to this question it's tough to begin at one place.
I'll just suggest some technologies because that seems to be what you're looking for. Ultimately I recommend you research this area and make up your own mind on what you'd like to use.
You can use a database to store the user information. NoSQL is popular nowadays so I'll go for a MongoDB solution http://www.mongodb.org/
You don't exactly need to use HTML tags as there are template solutions written for node.js. I recommend jade https://github.com/visionmedia/jade
There are frameworks and middleware created to make all of this easier. Check it out here https://github.com/joyent/node/wiki/modules

Categories

Resources