Skip to main content

Posts

Showing posts with the label MySQL

How to Export Data to CSV File using PHP and MySQL

CSV (comma-separated values) is the most popular file format to store tabular data in plain text. Generally, CSV file is used to import and export data for moving tabular data between programs. Import and export data is the most used feature in the web application, and CSV file format is a best chose for that. In the earlier tutorial, we have shown How to Import CSV File Data into MySQL Database using PHP . In this tutorial, we will show you how to export data from MySQL database to CSV file using PHP . Also, you will learn to create CSV file in PHP and download and save MySQL data in CSV file using PHP. To demonstrate Export to CSV functionality, we will build an example script which will export members data from the MySQL database and save in a CSV file using PHP. Create Table in MySQL Database The following SQL creates a members table with some basic fields in MySQL database. The members table holds the member’s information which needs to be exported. CREATE TABLE `memb...

Load Data on Page Scroll using jQuery Ajax PHP from MySQL Database

Previously we’ve published many tutorials on load data from MySQL database in PHP. For example our last article – Load more data using jQuery Ajax and PHP , where data are loaded from the database by clicking on the load more link. But in this article, we’ll do it differently. This tutorial will show an automatic process to load more data from the database in PHP. Here we’ll build script for load data on page scroll using jQuery, Ajax, and PHP . It will be very user-friendly because the data would be loaded from the MySQL database automatically while scrolling the page down. Users are not needed to click any link for data load. Let’s start the Load Data on Page Scroll with jquery and PHP tutorial. Before you begin, take a look on files structure. Database Table Creation Create a table named posts into the database (for example codexworld ). Example SQL query for creating posts table is given below. CREATE TABLE `posts` ( `id` int(11) NOT NULL AUTO_INCREMENT, `title` varcha...

PHP CRUD Operations without Page Refresh using jQuery Ajax MySQL

CRUD stands for Create, Read, Update and Delete database records. Add, Edit, Update, and Delete functionality is used almost every web project in PHP. You’ve done it many times, but today we’ll show you the more user-friendly way to implement CRUD functionality in PHP . Here we’ll implement PHP CRUD operations without page refresh using jQuery, Ajax, and MySQL. The functionality of the example script would be read, add, update, and delete the records from MySQL database. In this example script, we’ll fetch the users data from the database and display the user data list with add link, edit link, and delete link. By these links user can add new data to the database, update previously inserted data and delete the data from the database. All operations will happen on a single page without page refresh. Also, bootstrap table structure will be used for styling the list, form fields, and links. Let’s start the step-by-step guide on creating a CRUD application with PHP using jQuery Ajax MySQL...

PHP OOP CRUD Operations using PDO Extension and MySQL

In the earlier article, we’ve already published PHP CRUD functionality tutorial using Ajax . There we’ve using MySQLi to connect database and database-related operations. After publishing that article we received many requests from our readers for PHP CRUD tutorial with PDO extension and MySQL . They also mentioned that they are waiting for our tutorial because complete and clear PHP MySQL PDO tutorial was not found after huge searching. Waiting is over! Here we’ll show the view, add, edit, update, and delete operations using PDO in PHP. The PHP Data Objects (PDO) extension defines a consistent, lightweight interface for accessing databases in PHP. PDO extension provides a data-access abstraction layer, which means that you can use different databases using the same functions to queries and fetch data from the database. In this PHP PDO tutorial, through implementing the simple PHP CRUD operation you’ll learn PDO connection, PDO insert, PDO select, PDO update, PDO delete query managemen...

How to Import CSV File Data into MySQL Database using PHP

A CSV (comma-separated values) file stores the tabular data in plain text format. Basically, CSV file format is used to import to or export from the table data. Each line of the CSV file is a data record that consists of one or more fields. When there is needed to add the huge data into the MySQL database, it’s very time-consuming to add data one by one. In that situation, import feature helps to insert a bunch of data in one click. Using CSV file you can store all the data and import the CSV file data into the database at once using PHP and MySQL. Import CSV into MySQL helps to save the user time and avoid repetitive work. In this tutorial, we will show you how to upload and import CSV file data into MySQL database using PHP . Here we’ll build an example script to import members data into the database. According to this script functionality, the user would be able to upload a CSV file of members details and members data would be inserted into the MySQL database using PHP. Create Data...

How to Backup MySQL Database using PHP

Home   »   PHP   »   How to Backup MySQL Database using PHP The database backup is a most important task for every web developer. Regular database backup prevents risk to lose the data and it helps to restore the database if any issue occurred. So, backup the database whenever possible is a good idea. There many ways available to backup MySQL database in a file and you can backup database in one click from hosting server. But if you want to take MySQL database backup without login to your hosting server or phpMyAdmin, you can do it from the script using PHP. In this tutorial, we will build a PHP script to backup MySQL database and save in a SQL file . Perform MySQL Database Backup using PHP All the PHP code will be grouped together in backupDatabaseTables() function. Using backupDatabaseTables() function you can backup specific tables or all tables from a database. The following parameters are required to backup MySQL databas...

Store and Retrieve Image from MySQL Database using PHP

Generally, when we upload an image file in PHP , the uploaded image is stored in a directory of the server and the respective image name is inserted into the database. But if you want to upload an image without storing on the server, it can be done using MySQL database. If you’re concerned about the server space and need to free space on your server, you can insert an image file in the database without upload it to the directory. This procedure helps to optimize the server space because the image file content is stored in the database rather than the server. In this tutorial, we will show you how to store the image file into MySQL database and retrieve image from database using PHP . It’s very easy to store and retrieve images from the database using PHP and MySQL. Insert Image File in MySQL MySQL has a BLOB (binary large object) data type that can hold a large amount of binary data. The BLOB data type is perfect for storing the image data. In MySQL, four BLOB types are available – T...

'MySQLi' for Beginners

Introduction Nearly every site that you visit nowadays has some sort of database storage in place, many sites opt to use MySQL databases when using PHP. However, many people haven't yet taken the step to interacting with databases properly in PHP. Here we guide you through what you should be doing - using PHP's MySQLi class - with a hat-tip to the one way that you definitely shouldn't be doing it. The Wrong Way If you're using a function called mysql_connect() or mysql_query() you really need to take note and change what you're doing. I understand that it's not easy to change current large projects, but look to change future ones. Any of the functions that are prefixed with mysql_ are now being discouraged by PHP themselves as visible on this doc page , instead you should look to use one of the following: MySQLi - The i standing for 'improved'. PDO Each has its advantages, PDO for example will work with various different database systems, where as ...

MySQL Joins

Leading on from the earlier, basic introduction to using SQL. MySQL joins are very powerful, but can at times cause confusion. Do you go for a left join, a right join, or an inner join? What is the actual difference between them and how do you use them to pull information from two or more tables? The Basis A join is used where you have tables with a relationship, this might be a table that contains your users and one that contains all of the posts on your site. Within the posts table you'd have a column that contains the id of the user that wrote the post, this is a relationship to the id of the user in the users table. An example of the two tables and their data are below, we'll be using these to demonstrate the different types of joins and the result that they generate. The users table is on the left, and the posts table on the right: id username joined 1 michaelw90 2012-12-01 23:37:10 2 _d...