- MySQLi Tutorial
- MySQLi - Home
- MySQLi - Introduction
- MySQLi - PHP Syntax
- MySQLi - Connection
- MySQLi - Create Database
- MySQLi - Drop Database
- MySQLi - Select Database
- MySQLi - Create Tables
- MySQLi - Drop Tables
- MySQLi - Insert Query
- MySQLi - Select Query
- MySQLi - Where Clause
- MySQLi - Update Query
- MySQLi - Delete Query
- MySQLi - Like Clause
- MySQLi - Sorting Results
- MySQLi - Using Joins
- MySQLi - Handling NULL Values
- Obtaining & Using MySQLi Metadata
- MySQL
- MySQL - Installation
- MySQL - Administration
- MySQL - Data Types
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQLi Useful Resources
- MySQLi - Useful Functions
- MySQLi - Quick Guide
- MySQLi - Useful Resources
- MySQLi - Discussion
MySQLi - Query
Syntax
mixed mysqli_query ( mysqli $link , string $query [, int $resultmode = MYSQLI_STORE_RESULT ])
Definition and Usage
It is used to perform a query on the database.
Example
Try out following example −
<?php $servername = "localhost:3306"; $username = "root"; $password = ""; $dbname = "TUTORIALS"; $conn = new mysqli($servername, $username, $password, $dbname); if ($conn->connect_error) { die('Connect Error (' . mysqli_connect_errno() . ') '. mysqli_connect_error()); exit(); } echo 'Success... ' . mysqli_get_host_info($conn) . "\n"; $stmt = $conn->prepare("INSERT INTO tutorials_auto (id, name) VALUES (?, ?)"); $stmt->bind_param("is", $id, $name); $id = "10"; $name = "sai"; $stmt->execute(); echo "New records created successfully"; $stmt->close(); if ($result = $conn->query("SELECT name FROM tutorials_auto LIMIT 10")) { printf("Select returned %d rows.\n", $result->num_rows); $result->close(); } $conn->close(); ?>
The sample output of the above code should be like this −
Success... localhost:3306 via TCP/IP New records created successfully Select returned 3 rows.
mysqli_useful_functions.htm
Advertisements