Category: php Mysql

  • Khóa học miễn phí PHP & MySQL – Useful Resources nhận dự án làm có lương

    PHP & MySQL – Useful Resources



    The following resources contain additional information on PHP & MySQL. Please use them to get more in-depth knowledge on this topic.

    Useful Links on PHP & MySQL

    • − A complete resource for PHP stuff.

    • − PHP Extension and Application Repository, find a list of various useful PHP packages.

    • − Here you can download the latest MySQL release.

    • − Great articles and tutorials in PHP programming.

    • − A small article on PHP, worth to go through it.

    • − Create your website forum using phpBB. Very easy to customize and its open source, so you can download it free of cost and use it.

    Useful Books on PHP & MySQL

    To enlist your site on this page, please drop an email to contact@tutorialspoint.com


    Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc

  • Khóa học miễn phí PHP & MySQL – Discussion nhận dự án làm có lương

    Discuss PHP & MySQL



    PHP provides various functions to access the MySQL database and to manipulate the data records inside the MySQL database. You would require to call the PHP functions in the same way you call any other PHP function.



    Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc

  • Khóa học miễn phí PHP & MySQL – Drop Database nhận dự án làm có lương

    PHP & MySQL – Drop Database Example



    PHP uses mysqli query() or mysql_query() function to drop a MySQL database. This function takes two parameters and returns TRUE on success or FALSE on failure.

    Syntax

    $mysqli->query($sql,$resultmode)
    

    Sr.No. Parameter & Description
    1

    $sql

    Required – SQL query to drop a MySQL database.

    2

    $resultmode

    Optional – Either the constant MYSQLI_USE_RESULT or MYSQLI_STORE_RESULT depending on the desired behavior. By default, MYSQLI_STORE_RESULT is used.

    Example

    Try the following example to drop a database −

    Copy and paste the following example as mysql_example.php −

    <html>
       <head><title>Dropping MySQL Database</title></head>
       <body>
          <?php
             $dbhost = ''localhost
             $dbuser = ''root
             $dbpass = ''root@123
             $mysqli = new mysqli($dbhost, $dbuser, $dbpass);
    
             if($mysqli->connect_errno ) {
                printf("Connect failed: %s<br />", $mysqli->connect_error);
                exit();
             }
             printf(''Connected successfully.<br />'');
    
             if ($mysqli->query("Drop DATABASE TUTORIALS")) {
                printf("Database TUTORIALS dropped successfully.<br />");
             }
             if ($mysqli->errno) {
                printf("Could not drop database: %s<br />", $mysqli->error);
             }
             $mysqli->close();
          ?>
       </body>
    </html>
    

    Output

    Access the mysql_example.php deployed on apache web server and verify the output.

    Connected successfully.
    Database TUTORIALS dropped successfully.
    

    Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc

  • Khóa học miễn phí PHP & MySQL – Create Tables nhận dự án làm có lương

    PHP & MySQL – Create Table



    PHP uses mysqli query() or mysql_query() function to create a MySQL table. This function takes two parameters and returns TRUE on success or FALSE on failure.

    Syntax

    $mysqli->query($sql,$resultmode)
    

    Sr.No. Parameter & Description
    1

    $sql

    Required – SQL query to create a MySQL table.

    2

    $resultmode

    Optional – Either the constant MYSQLI_USE_RESULT or MYSQLI_STORE_RESULT depending on the desired behavior. By default, MYSQLI_STORE_RESULT is used.

    Example

    Try the following example to create a table −

    Copy and paste the following example as mysql_example.php −

    <html>
       <head>
          <title>Creating MySQL Table</title>
       </head>
       <body>
          <?php
             $dbhost = ''localhost
             $dbuser = ''root
             $dbpass = ''root@123
             $dbname = ''TUTORIALS
             $mysqli = new mysqli($dbhost, $dbuser, $dbpass, $dbname);
    
             if($mysqli->connect_errno ) {
                printf("Connect failed: %s<br />", $mysqli->connect_error);
                exit();
             }
             printf(''Connected successfully.<br />'');
             $sql = "CREATE TABLE tutorials_tbl( ".
                "tutorial_id INT NOT NULL AUTO_INCREMENT, ".
                "tutorial_title VARCHAR(100) NOT NULL, ".
                "tutorial_author VARCHAR(40) NOT NULL, ".
                "submission_date DATE, ".
                "PRIMARY KEY ( tutorial_id )); ";
             if ($mysqli->query($sql)) {
                printf("Table tutorials_tbl created successfully.<br />");
             }
             if ($mysqli->errno) {
                printf("Could not create table: %s<br />", $mysqli->error);
             }
             $mysqli->close();
          ?>
       </body>
    </html>
    

    Output

    Access the mysql_example.php deployed on apache web server and verify the output.

    Connected successfully.
    Table tutorials_tbl created successfully.
    

    Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc

  • Khóa học miễn phí PHP & MySQL – Overview nhận dự án làm có lương

    PHP & MySQL – Overview



    MySQL works very well in combination of various programming languages like PERL, C, C++, JAVA and PHP. Out of these languages, PHP is the most popular one because of its web application development capabilities.

    PHP provides various functions to access the MySQL database and to manipulate the data records inside the MySQL database. You would require to call the PHP functions in the same way you call any other PHP function.

    The PHP functions for use with MySQL have the following general format −

    mysql_function(value,value,...);
    

    The second part of the function name is specific to the function, usually a word that describes what the function does. The following are two of the functions, which we will use in our tutorial −

    mysqli_connect($connect);
    mysqli_query($connect,"SQL statement");
    

    The following example shows a generic syntax of PHP to call any MySQL function.

    <html>
       <head>
          <title>PHP with MySQL</title>
       </head>
    
       <body>
          <?php
             $retval = mysql_function(value, [value,...]);
             if( !$retval ) {
                die ( "Error: a related error message" );
             }
             // Otherwise MySQL or PHP Statements
          ?>
       </body>
    </html>
    

    Starting from the next chapter, we will see all the important MySQL functionality along with PHP.


    Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc

  • Khóa học miễn phí PHP & MySQL – Environment Setup nhận dự án làm có lương

    PHP & MySQL – Environment Setup



    In order to develop and run PHP Web pages, three vital components need to be installed on your computer system.

    • Web Server − PHP works with virtually all Web Server software, including Microsoft”s Internet Information Server (IIS) but most often used is Apache Server. Download Apache for free here −

    • Database − PHP works with virtually all database software, including Oracle and Sybase but most commonly used is MySQL database. Download MySQL for free here −

    • PHP Parser − In order to process PHP script instructions, a parser must be installed to generate HTML output that can be sent to the Web Browser. This tutorial will guide you how to install PHP parser on your computer.

    PHP Parser Installation

    Before you proceed, it is important to make sure that you have proper environment setup on your machine to develop your web programs using PHP. Store the following php file in Apache”s htdocs folder.

    phpinfo.php

    <?php
       phpinfo();
    ?>
    

    Type the following address into your browser”s address box.

    http://127.0.0.1/phpinfo.php
    

    If this displays a page showing your PHP installation related information, then it means you have PHP and Webserver installed properly. Otherwise, you have to follow the given procedure to install PHP on your computer.

    This section will guide you to install and configure PHP over the following four platforms −

    Apache Configuration

    If you are using Apache as a Web Server, then this section will guide you to edit Apache Configuration Files.

    Check here −

    PHP.INI File Configuration

    The PHP configuration file, php.ini, is the final and immediate way to affect PHP”s functionality.

    Check here −

    Windows IIS Configuration

    To configure IIS on your Windows machine, you can refer your IIS Reference Manual shipped along with IIS.

    Install MySQL Database

    The most important thing you will need, of course is an actual running database with a table that you can query and modify.

    • MySQL DB − MySQL is an open source database. You can download it from . We recommend downloading the full Windows installation.

    • In addition, download and install as well as These are GUI based tools that will make your development much easier.

    • Finally, download and unzip (the MySQL JDBC driver) in a convenient directory. For the purpose of this tutorial we will assume that you have installed the driver at C:Program FilesMySQLmysql-connector-java-5.1.8.

    • Accordingly, set CLASSPATH variable to C:Program FilesMySQLmysql-connector-java-5.1.8mysql-connector-java-5.1.8-bin.jar. Your driver version may vary based on your installation.

    Set Database Credential

    When we install MySQL database, its administrator ID is set to root and it gives provision to set a password of your choice.

    Using root ID and password you can either create another user ID and password, or you can use root ID and password for your JDBC application.

    There are various database operations like database creation and deletion, which would need administrator ID and password.

    For rest of the JDBC tutorial, we would use MySQL Database with guest as ID and guest123 as password.

    If you do not have sufficient privilege to create new users, then you can ask your Database Administrator (DBA) to create a user ID and password for you.

    Create Database

    To create the TUTORIALSPOINT database, use the following steps −

    Step 1

    Open a Command Prompt and change to the installation directory as follows −

    C:>
    C:>cd Program FilesMySQLbin
    C:Program FilesMySQLbin>
    

    Note − The path to mysqld.exe may vary depending on the install location of MySQL on your system. You can also check documentation on how to start and stop your database server.

    Step 2

    Start the database server by executing the following command, if it is already not running.

    C:Program FilesMySQLbin>mysqld
    C:Program FilesMySQLbin>
    

    Step 3

    Create the TUTORIALSPOINT database by executing the following command −

    C:Program FilesMySQLbin> mysqladmin create TUTORIALSPOINT -u guest -p
    Enter password: ********
    C:Program FilesMySQLbin>
    

    Create Table

    To create the Employees table in TUTORIALSPOINT database, use the following steps −

    Step 1

    Open a Command Prompt and change to the installation directory as follows −

    C:>
    C:>cd Program FilesMySQLbin
    C:Program FilesMySQLbin>
    

    Step 2

    Login to the database as follows −

    C:Program FilesMySQLbin>mysql -u guest -p
    Enter password: ********
    mysql>
    

    Step 3

    Create the table Employees as follows −

    mysql> use TUTORIALSPOINT;
    mysql> create table Employees
       -> (
       -> id int not null,
       -> age int not null,
       -> first varchar (255),
       -> last varchar (255)
       -> );
    Query OK, 0 rows affected (0.08 sec)
    mysql>
    

    Create Data Records

    Finally you create few records in Employee table as follows −

    mysql> INSERT INTO Employees VALUES (100, 18, ''Zara'', ''Ali'');
    Query OK, 1 row affected (0.05 sec)
    
    mysql> INSERT INTO Employees VALUES (101, 25, ''Mahnaz'', ''Fatma'');
    Query OK, 1 row affected (0.00 sec)
    
    mysql> INSERT INTO Employees VALUES (102, 30, ''Zaid'', ''Khan'');
    Query OK, 1 row affected (0.00 sec)
    
    mysql> INSERT INTO Employees VALUES (103, 28, ''Sumit'', ''Mittal'');
    Query OK, 1 row affected (0.00 sec)
    
    mysql>
    

    For a complete understanding on MySQL database, study the .

    Now you are ready to start experimenting with PHP.


    Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc

  • Khóa học miễn phí PHP & MySQL – Home nhận dự án làm có lương

    PHP MySQL Tutoriall

    PHP & MySQL Tutorial







    PHP provides various functions to access the MySQL database and to manipulate the data records inside the MySQL database. You would require to call the PHP functions in the same way you call any other PHP function.

    Audience

    This tutorial is designed for Java programmers who would like to understand the PHP functions to connect to MySQL in detail and actual usage.

    Prerequisites

    Before proceeding with this tutorial, you should have a good understanding of PHP programming language. As you are going to deal with MySQL database, you should have prior exposure to SQL and Database concepts.

    Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc

  • Khóa học miễn phí PHP & MySQL – Select Database nhận dự án làm có lương

    PHP & MySQL – Select Database Example



    PHP uses mysqli_select_db function to select the database on which queries are to be performed. This function takes two parameters and returns TRUE on success or FALSE on failure.

    Syntax

    mysqli_select_db ( mysqli $link , string $dbname ) : bool
    

    Sr.No. Parameter & Description
    1

    $link

    Required – A link identifier returned by mysqli_connect() or mysqli_init().

    2

    $dbname

    Required – Name of the database to be connected.

    Example

    Try the following example to select a database −

    Copy and paste the following example as mysql_example.php −

    <html>
       <head>
          <title>Selecting MySQL Database</title>
       </head>
       <body>
          <?php
             $dbhost = ''localhost
             $dbuser = ''root
             $dbpass = ''root@123
             $conn = mysqli_connect($dbhost, $dbuser, $dbpass);
    
             if(! $conn ) {
                die(''Could not connect: '' . mysqli_error($conn));
             }
             echo ''Connected successfully<br />
             $retval = mysqli_select_db( $conn, ''TUTORIALS'' );
    
             if(! $retval ) {
                die(''Could not select database: '' . mysqli_error($conn));
             }
             echo "Database TUTORIALS selected successfullyn";
             mysqli_close($conn);
          ?>
       </body>
    </html>
    

    Output

    Access the mysql_example.php deployed on apache web server and verify the output.

    Database TUTORIALS selected successfully
    

    Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc

  • Khóa học miễn phí PHP & MySQL – Drop Tables nhận dự án làm có lương

    PHP & MySQL – Drop Table Example



    PHP uses mysqli query() or mysql_query() function to drop a MySQL table. This function takes two parameters and returns TRUE on success or FALSE on failure.

    Syntax

    $mysqli->query($sql,$resultmode)
    

    Sr.No. Parameter & Description
    1

    $sql

    Required – SQL query to drop a table.

    2

    $resultmode

    Optional – Either the constant MYSQLI_USE_RESULT or MYSQLI_STORE_RESULT depending on the desired behavior. By default, MYSQLI_STORE_RESULT is used.

    Example

    Try the following example to drop a table −

    Copy and paste the following example as mysql_example.php −

    <html>
       <head><title>Dropping MySQL Table</title></head>
       <body>
          <?php
             $dbhost = ''localhost
             $dbuser = ''root
             $dbpass = ''root@123
             $dbname = ''TUTORIALS
             $mysqli = new mysqli($dbhost, $dbuser, $dbpass, $dbname);
    
             if($mysqli->connect_errno ) {
                printf("Connect failed: %s<br />", $mysqli->connect_error);
                exit();
             }
             printf(''Connected successfully.<br />'');
    
             if ($mysqli->query("Drop Table tutorials_tbl")) {
                printf("Table tutorials_tbl dropped successfully.<br />");
             }
             if ($mysqli->errno) {
                printf("Could not drop table: %s<br />", $mysqli->error);
             }
             $mysqli->close();
          ?>
       </body>
    </html>
    

    Output

    Access the mysql_example.php deployed on apache web server and verify the output.

    Connected successfully.
    Table tutorials_tbl dropped successfully.
    

    Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc

  • Khóa học miễn phí PHP & MySQL – Connect Database nhận dự án làm có lương

    PHP & MySQL – Connect Database Example



    PHP provides mysqli contruct or mysqli_connect() function to open a database connection. This function takes six parameters and returns a MySQL link identifier on success or FALSE on failure.

    Syntax

    $mysqli = new mysqli($host, $username, $passwd, $dbName, $port, $socket);
    

    Sr.No. Parameter & Description
    1

    $host

    Optional − The host name running the database server. If not specified, then the default value will be localhost:3306.

    2

    $username

    Optional − The username accessing the database. If not specified, then the default will be the name of the user that owns the server process.

    3

    $passwd

    Optional − The password of the user accessing the database. If not specified, then the default will be an empty password.

    4

    $dbName

    Optional − database name on which query is to be performed.

    5

    $port

    Optional − the port number to attempt to connect to the MySQL server..

    6

    $socket

    Optional − socket or named pipe that should be used.

    You can disconnect from the MySQL database anytime using another PHP function close().

    Syntax

    $mysqli->close();
    

    Example

    Try the following example to connect to a MySQL server −

    Copy and paste the following example as mysql_example.php −

    <html>
       <head>
          <title>Connecting MySQL Server</title>
       </head>
       <body>
          <?php
             $dbhost = ''localhost
             $dbuser = ''root
             $dbpass = ''root@123
             $mysqli = new mysqli($dbhost, $dbuser, $dbpass);
    
             if($mysqli->connect_errno ) {
                printf("Connect failed: %s<br />", $mysqli->connect_error);
                exit();
             }
             printf(''Connected successfully.<br />'');
             $mysqli->close();
          ?>
       </body>
    </html>
    

    Output

    Access the mysql_example.php deployed on apache web server and verify the output.

    Connected successfully.
    

    Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc