المشاركات

عرض الرسائل ذات التصنيف MySQL

How to Change Apache and MySQL Port Number in XAMPP Localhost

صورة
Hi! I'm going to show you how to change the apache and mysql port number in xampp localhost . In case you wonder why you should change the port number of a web server, here is the answer. It's not unlikely for you to run multiple PHP versions on a same machine or to run IIS or JBoss simultaneously with Apache. When you start a web server, it occupies the default HTTP port '80'. If you try to run the second one, it will fail since the port is already occupied. So unless you change the port for the latter, you can't run more than one web server at once. Below we will see the ways to change the port no. for apache and mysql. To Change Apache Port Number: Stop Apache server and exit XAMPP control panel if it is already running. First you must change the HTTP port. Go to [path-to-xampp-folder]/apache/conf folder and open http.conf file. The default port for Apache is '80'. Unless you have changed it, this is the port number you must replace. Now look f...

How to Import CSV File into MySQL with LOAD DATA INFILE

صورة
I tried to import a csv file into mysql with php script . It is a simple solution if you have a small set of data to import. But if you have hundreds of thousands of records, don't even think about it. You need something different to read through a large dataset quickly. MySQL's LOAD DATA INFILE command works like a charm and can be executed from the command line. Using LOAD DATA INFILE allows you to load csv or any other delimited data file to the mysql table with a single command. It comes with several options and we will see below what they are and how to use them to import the csv data set into the mysql table. Using LOAD DATA INFILE Command: The LOAD DATA INFILE command in mysql loads data from a file into the table at high speed. The file path specified must be absolute or relative. 1. Importing CSV File into MySQL: Let's say we have a mysql table 'customers' with the following structure. MySQL Table: Customers CREATE TABLE `customers`( `id` INT...

Dynamic Treeview Menu using PHP, MySQL and AJAX Example

صورة
How to Create Dynamic Treeview Menu using PHP, MySQL and AJAX? Most modern websites use tree view to display the dynamic sidebar menu for easy navigation. In case you don't know, a Treeview is a hierarchical representation of elements in a tree-like structure. You can go for jquery solution in this context, but I would recommend 'Bootstrap Treeview' plug-in if you use the bootstrap framework to build your websites. The plug-in uses JSON dataset to create a hierarchical tree structure. I have already discussed the creation of static treeview menu using bootstrap treeview . But you can also generate a dynamic tree where you pull off the data elements stored in the database. In this tutorial I'm going to show you about creating dynamic treeview using php, mysql, ajax and bootstrap. How to Create Dymanic Treeview in PHP & MySQL? For the demo, I'm going to load all the required libraries via CDN. So there's no need to download them to your web server. Here...

How to Find the Second Highest Salary with MySQL Query

صورة
Hi! Today's post is about a popular interview question, which is the sql query to find the second highest salary . Most freshers would have faced this question in their interviews. There is not one single solution for this. You can approach in different ways to get the second maximum salary from the database. Here I'm going to show you some of the best possible ways you can write the sql query to fetch the salary that is second highest. I've tried these queries on MySQL but it also works with other relational databases such as MSSQL Server, Oracle etc., that uses SQL. Finding the Second Highest Salary: Consider the following table. It consists of a set of employee records and we are going to use in our queries to get salary that is second largest. Table Name: Employees ID Name Designation Salary 1 Colleen Hurst Regional Director 205500 2 Garrett Winters Ac...

How to Export MySQL Table to JSON File in CodeIgniter

صورة
Hi! In this tutorial, we will see how to export mysql table to json file in codeigniter . Data portability has become more important than ever and a necessary requirement for modern applications. Almost all web services uses JSON format to migrate data from one location to another. So, as a Web Developer, you must know to handle json and various types of applications like Web, Mobile etc. Exporting mysql into json allows you to easily port data to different platforms. The whole process is quite simple. Just fetch the data from mysql database, covert the query result to json and then write it in a file. CodeIgniter - Export MySQL Table to JSON File: Let's create a demo for exporting the database as json. The steps are easy to follow and we possibly need two files, a model and a controller. Step-1) Create Database We need a dummy database to use in the example, a database, a table and some sample records. Run the below sql file in the mysql environment and create them. ...

jQuery Datatables with PHP, MySQL and AJAX Example

صورة
Hi! In this tutorial let's look at the server-side processing of jquery datatables using php, mysql and ajax . In case you don't know, Datatables is an amazing jquery plugin that converts the simple html table into a feature-rich data grid with additional functions like instant search, pagination, multi-column sorting etc. The table works with multiple data sources like DOM, AJAX etc., and supports both client and server side processing. We have already seen about datatables with json data and here we will see about server side processing. For the server script, we are going to use PHP and MySQL as a data source. jQuery Datatables Server-side Processing with PHP and MySQL: Let's see how to fetch records from the server-side using ajax request and list it in the data tables. To use in this example, we need a dummy database. So let's create it first. Step 1) Create MySQL Database The following sql will create a mysql database, a table and some sample records i...

Connect to Multiple Databases with PHP MySQLi and PDO

صورة
Hi! In this tutorial, we'll see how to connect to multiple databases using PHP's MySQLi and PDO (PHP Data Object) library. At times you may want to work with multiple mysql databases in the same context. Therefore, you need to connect to two or more databases in the same mysql instance and fetch data from them simultaneously. The old 'MySQL' extension has been deprecated since PHP5.5, so I would recommend you to use 'MySQLi' or even better 'PDO' , which provides an additional layer of security and supports multiple databases such as MySQL, MSSQL Server, PostgreSQL, Oracle and much more. The databases can be on the same server as php script or on different server. No matter what, connecting php to remote mysql server is similar to the one on the same server, except that you must provide permission to access the remote database. Connecting Multiple Databases with PHP MySQLi: Establishing connection to multiple databases using mysqli api is eas...

Autocomplete Textbox using HTML5 Datalist, PHP and MySQL Example

صورة
Autosuggest Textbox is a cool technique to enhance user experience in websites. It's a google like search box which pops up suggestions while you type and lets you choose the word(s) without typing it completely. Usually this feature requires third party tools like jquery plug-ins to implement but thanks to HTML5, you can do it with plain html and php alone. In this tutorial, I'm going to show you, how easy it is to integrate HTML5 auto complete textbox from database using PHP and MySQL. Autocomplete Textbox from Database using HTML5 and PHP The HTML5 DATALIST element adds up autocomplete feature to ordinary textboxes and it takes up several options similar to SELECT element. To implement auto suggest from database, we should fetch the data and populate it to the datalist options. Finally integrate this datalist to a textbox element and we are done. Let's see how to do it in php and mysql. Step-1: Connect to MySQL Database in PHP First establish the connectio...

CodeIgniter Database CRUD Tutorial for Beginners with Examples

صورة
CRUD is one of the primary functions of a Database Management System. It stands for the four basic operations Create, Read, Update and Delete performed on databases. In SQL, it represents INSERT (Create), SELECT (Read), UPDATE (Update) and DELETE (Delete) commands. Learning the Database CRUD process is essential in application development especially when you want to work with databases. In this codeigniter tutorial, we'll see about building database CRUD operations using CodeIgniter and MySQL Database in detail. Building Database CRUD Operations in CodeIgniter To understand CRUD in a simple way, let us consider an example say you develop a web application which handles employee details of a business venture. At the minimum level the application should allow to add (Create), list (Read), update and delete the employee records. So to implement a CRUD process in applications, you should develop some user interface for the user to perform the above said tasks. Codeigniter f...

Inline Editing using PHP MySQL and jQuery AJAX

صورة
Hi! Today we will see about ajax inline editing using php and mysql . Inline editing allows users to rapidly modify web page contents in place without the requirement of forms. Popular sites like Facebook, Twitter, etc. employ this technique so that users can change their profile information without having to navigate through separate forms. Using HTML5's 'contenteditable' on page elements will take care of inline editing. For example, you can convert a plain html table into an editable table by setting 'contenteditable = true'. If you are new to inline editing, take a look at html5 editable table tutorial . PHP MySQL Inline Editing using jQuery AJAX: The 'contenteditable' attribute can be used on almost all html elements, but the data edited by user is only temporary. It will be lost when the page is refreshed. Therefore, you must use ajax to send the data back to the server and store it in database for future use. Here, let's see a demo wit...

How to Reset MySQL Auto Increment Counter

Hi! If you are newbie to MySQL, then you will definitely benefit from this tip I’m going to share today. Auto Increment Counter is one of the prominent feature of MySQL Database and it’s a general practiced way to set the primary key columns to auto increment indexing. By this way whenever a new row is inserted, the counter increments automatically by ‘1’. But the method has one limitation to it for the auto-increment counter will not reset the value by itself even if you delete all the entries in the table. Imagine you have a mysql table with a bunch of data say 10 rows already but you want to delete and start with fresh set of entries. In such case even if you delete all those rows, the new record would start from ‘11’ and not ‘1’ for auto increment column. But this doesn’t mean you can’t reset it by yourself. Reset Auto Increment Counter in MySQL Dropping a table and recreating it will reset auto-increment counter to start from ‘1’ but this is not very desirable solution an...

How to CREATE & DROP INDEX in MySQL Database Table

صورة
DATABASE INDEX is used to find, sort and group the data in a fast and efficient way. These indexes can be created using one or more columns and creating index to a column generates an extra hidden column holding the same data sorted with a handle to the original data. Hence it allows the database application to find the data fast without reading the whole table. Today we’ll see how to create and drop index in mysql database table. Don’t Miss: How to Read HTTP Headers in PHP Create Index in MySQL Database Table To create index in mysql table we should use CREATE INDEX statement like this, CREATE INDEX bk_index ON books (book_name); It creates an index with the name ‘bk_index’ for the field (column) ‘book_name’ in the table ‘books’. Create Index for Multiple Columns We can also create index for a combination of two or more fields by listing the field names separated by comma inside the parenthesis like this, CREATE INDEX bk_index ON books (book_name, author_name); Create...

How to Backup and Restore MySQL Database using Command Line

صورة
It’s a good practice to regularly backup the databases to avoid losing data. And at times you may want to move the database from development to production environment or to some remote server. Either way you have to backup the database, and this mysql tutorial will show you the simple way to backup and restore mysql database using command line. MySQL Database Management System provides a powerful utility called ‘mysqldump’ which is available with the mysql installation and you can find it inside the ‘bin’ directory. How to Backup and Restore MySQL Database using Command Line You can use the ‘mysqldump’ command line utility to create dumps of one or more mysql databases and even generates the output as csv, sql or xml file. The dumps contains the set of sql commands (like DROP, CREATE, INSERT) required to reproduce the databases from scratch. Backup MySQL Database using mysqldump Command Use the mysqldump command to backup the database like this, $ mysqldump [option] -u [u...

How to Connect to Multiple Databases in CodeIgniter

صورة
Connecting to multiple databases is simpler in CodeIgniter . All you have to do is to establish a separate connection for each database you wish to work. At times you may want to work with multiple databases from same or different servers. In core PHP, you can do it by creating separate connection object. And in codeigniter you have to set up separate connection settings for each database you wish to connect. Here I'll show you how to connect with two MySQL Databases . Connecting to Mulitiple Databases in CodeIgniter 1. Open the "application/config/database.php" file. 2. You can see a list of default connection settings provided. Now enter the hostname, username, password, database & database prefix (if any) you want to connect. $db['default']['hostname'] = 'localhost'; $db['default']['username'] = 'mysql_username'; $db['default']['password'] = 'mysql_password'; $db['default']...

How to Fetch Data from Database in CodeIgniter

صورة
How to fetch data from database in codeigniter? CodeIgniter is the simplest and light PHP framework which lets you create robust web applications in no time. Using Twitter Bootstrap with CodeIgniter saves the hassle of writing CSS Stylesheets for your app and lets you focus on development. Later you can customize bootstrap styles to suit your need. That is the best part of using MVC pattern as the presentation (view) is separate, you can change the look and feel of the app anytime without disturbing the rest of it. kodingmadesimple.com have good amount of twitter bootstrap tutorials about customizing bootstrap 3 and I recommend you to go through our bootstrap tutorials section. Fetch Data from Database in CodeIgniter: Now we'll see how to read data from MySQL Database and display it in a neat table format with Bootstrap. Since we are going to use bootstrap we don't want to write any custom stylesheets for formatting the display. If you are not familiar with using B...

CodeIgniter Bootstrap: Insert Form Data into Database

صورة
Hi, this CodeIgniter Bootstrap Tutorial will teach you How to Insert Form Data into MySQL Database using CodeIgniter, Bootstrap CSS framework and jQuery UI . I'm going to walk you through step-by-step, creating a form in codeigniter and insert those form data into database. To design the said php codeigniter form, we use twitter boostrap css framework and it's one of my all time favorite and saves time from creating style sheets of our own. If you wonder how to use bootstrap in codeigniter, then read this tutorial on Integrating Bootstrap with CodeIgniter . MySQL Database Example I'm going to use mysql database as an example for this tutorial. Here, take a look at the sample employee database I have. The fields that are highlighted in yellow color are primary keys and those ones in green are foreign keys. Now run this sql query in mysql to create the above database. SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO"; CREATE TABLE IF NOT EXISTS `tbl_department` ( ...