PHP API FOR NEWS
Is a class that can simplify your work to create your custom blog page or a news website.
How it works?
- Include the class in your PHP script. Example: include "ra-news-class.php";
- Make sure that you have properly created a database or atleast you have existing one.
- After that you have to set the database variables in the following way:
- $server_name = $_YOUR_SERVER_NAME;
- $db_name = $_YOUR_DATABASE_NAME;
- $db_user = $_THE_USER_OF_YOUR_DATABASE;
- $db_pass = $_THE_PASSWORD_OF_YOUR_DATABASE;
- $stories_table: The table where we are going to store the stories. By default it is "ra_news_stories".
- Once you've set the Database & the DB variables you are ready to call the RA_NEWS class. Example: $news_demo = new RA_NEWS( true, $server_name, $db_name, $db_user, $db_pass );
- The class takes 6 arguments:
- $debug - By default it is set to false but if it's true the class will return the errors if any occurs.
- $server_name - The name of the HOST SERVER.
- $db_name - The name of the Database.
- $db_user - The Database user.
- $db_pass - The password of the Database user.
- $stories_table - The table which to be created / used for the stories.
id int NOT NULL AUTO_INCREMENT,story_title LONGTEXT,story_publish_date DATE,story_text LONGTEXT,PRIMARY KEY (id)
- Structure of the stories table:
- Now you are ready to play around with the class methods.
- The methods are:
- initialize_db() - Is used to create the table for the news in the database if we already don't have it.
- add_story( $title_, $content_, $date_ = "" ) - Is used to create a new story in the News table. A specific $title_, $content_ & $date_ can be provided as arguments.
- edit_story( $id, $title_ = "", $content_ = "", $date_ = "" ) - Is used to edit a story that already exists in the DB. The ID selector of the specific story can be provided by the $id var and the new title, content & date can be provided by $title_, $content_ & $date_. Note: If they are empty the specific field won't be updated in the DB.
- delete_story( $id ) - Is used to delete a story from the DB. The ID selector of the specific story can be provided by the $id var.
- get_story( $id ) - Is used to return story from the DB. The ID selector of the specific story can be provided by the $id var. Ther returned result is in JSON object.