JoelWebsites Posted January 8, 2015 Share Posted January 8, 2015 (edited) I want to insert the following below code into my module ..the below code creates an api ...How do I insert this code in prestashop.. The code is taken from a php file which has generated a api sucessfully. <?php //if(isset($_GET['format']) && intval($_GET['num'])) { //Set our variables $format = strtolower($_GET['format']); $num = intval($_GET['num']); $db_host = "127.0.0.1"; // Place the username for the MySQL database here $db_username = "*********1231"; // Place the password for the MySQL database here $db_pass = "*(&(&*$@##$"; // Place the name for the MySQL database here $db_name = "$&**^#$@"; // Run the actual connection here mysql_connect("$db_host","$db_username","$db_pass") or die ("could not connect to mysql"); mysql_select_db("$db_name") or die ("no database"); //Run our query $result = mysql_query('SELECT * FROM ps_employee ') or die('MySQL Error.'); //Preapre our output if($format == 'json') { $recipes = array(); while($recipe = mysql_fetch_array($result, MYSQL_ASSOC)) { $recipes[] = array('post'=>$recipe); } $output = json_encode(array('posts' => $recipes)); } elseif($format == 'xml') { header('Content-type: text/xml'); $output = "<?xml version=\"1.0\"?>\n"; $output .= "<recipes>\n"; for($i = 0 ; $i < mysql_num_rows($result) ; $i++){ $row = mysql_fetch_assoc($result); $output .= "<recipe> \n"; $output .= "<recipe_id>" . $row['id_employee'] . "</recipe_id> \n"; $output .= "<recipe_name>" . $row['email'] . "</recipe_name> \n"; } $output .= "</recipes>"; } else { die('Improper response format.'); } //Output the output. echo $output; //} ?> Edited January 8, 2015 by joeljfernandes (see edit history) Link to comment Share on other sites More sharing options...
bellini13 Posted January 8, 2015 Share Posted January 8, 2015 you don't appear to be using any Prestashop code here, why not just put this into a php file (like api.php) and put that file into the root of your store? Link to comment Share on other sites More sharing options...
JoelWebsites Posted January 8, 2015 Author Share Posted January 8, 2015 Yes your correct it works directly..but can you please tell me how to use the same code in prestashop..thanks for the reply Link to comment Share on other sites More sharing options...
GOKULAN R Posted November 29, 2017 Share Posted November 29, 2017 Hi, I want sample APi Created File and which location i put that file (FolderName) root path Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now